summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/tclIOUtil.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c
index d5bb102..5a8d022 100644
--- a/generic/tclIOUtil.c
+++ b/generic/tclIOUtil.c
@@ -1755,7 +1755,9 @@ Tcl_FSEvalFile(interp, pathPtr)
* [Bug: 2040]
*/
Tcl_SetChannelOption(interp, chan, "-eofchar", "\32");
- /* Try to read utf-8 BOM, if available */
+ /* 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 \"",
@@ -1763,6 +1765,10 @@ Tcl_FSEvalFile(interp, pathPtr)
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);