diff options
Diffstat (limited to 'generic')
| -rw-r--r-- | generic/tclEncoding.c | 4 | ||||
| -rw-r--r-- | generic/tclIOUtil.c | 17 |
2 files changed, 18 insertions, 3 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index 2e0d51f..a4bea31 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -984,13 +984,13 @@ Tcl_GetEncodingNames( int Tcl_SetSystemEncoding( Tcl_Interp *interp, /* Interp for error reporting, if not NULL. */ - CONST char *name) /* The name of the desired encoding, or NULL + CONST char *name) /* The name of the desired encoding, or NULL/"" * to reset to default encoding. */ { Tcl_Encoding encoding; Encoding *encodingPtr; - if (name == NULL) { + if (!name || !*name) { Tcl_MutexLock(&encodingMutex); encoding = defaultEncoding; encodingPtr = (Encoding *) encoding; diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c index e714471..44849d1 100644 --- a/generic/tclIOUtil.c +++ b/generic/tclIOUtil.c @@ -1788,7 +1788,22 @@ Tcl_FSEvalFileEx( objPtr = Tcl_NewObj(); Tcl_IncrRefCount(objPtr); - if (Tcl_ReadChars(chan, objPtr, -1, 0) < 0) { + /* Try to read first character of stream, so we can + * check for utf-8 BOM to be handled especially. + */ + if (Tcl_ReadChars(chan, objPtr, 1, 0) < 0) { + Tcl_Close(interp, chan); + Tcl_AppendResult(interp, "couldn't read file \"", + Tcl_GetString(pathPtr), "\": ", Tcl_PosixError(interp), NULL); + goto end; + } + string = Tcl_GetString(objPtr); + /* + * If first character is not a BOM, append the remaining characters, + * otherwise replace them [Bug 3466099]. + */ + if (Tcl_ReadChars(chan, objPtr, -1, + memcmp(string, "\xef\xbf\xbe", 3)) < 0) { Tcl_Close(interp, chan); Tcl_AppendResult(interp, "couldn't read file \"", Tcl_GetString(pathPtr), "\": ", Tcl_PosixError(interp), NULL); |
