summaryrefslogtreecommitdiffstats
path: root/generic/tclIOUtil.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-02-29 21:34:46 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-02-29 21:34:46 (GMT)
commit4c1377ed5aa3f0187be137f191a760ea2c9c2f18 (patch)
tree429c25c751c106db85c75db6345c91296dc73692 /generic/tclIOUtil.c
parentfbbaada7c6f41c2d812462097bb2bd959e516491 (diff)
parenta1416a6c397598835f3c599368c200d6e5402223 (diff)
downloadtcl-4c1377ed5aa3f0187be137f191a760ea2c9c2f18.zip
tcl-4c1377ed5aa3f0187be137f191a760ea2c9c2f18.tar.gz
tcl-4c1377ed5aa3f0187be137f191a760ea2c9c2f18.tar.bz2
[Bug 3466099] BOM in Unicode
Diffstat (limited to 'generic/tclIOUtil.c')
-rw-r--r--generic/tclIOUtil.c17
1 files changed, 16 insertions, 1 deletions
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);