summaryrefslogtreecommitdiffstats
path: root/generic/tclIOUtil.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-02-29 21:17:35 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-02-29 21:17:35 (GMT)
commit70ea61c893a776323211dbc1d3b5d1d10c7d745e (patch)
tree73adf39b2338a6a278e999cfa368b35c224c87d3 /generic/tclIOUtil.c
parent7695d3270788d56c1ba433909285dcab42414edb (diff)
parent725269055e427aba43ac90a8c1cc56645adeeefa (diff)
downloadtcl-70ea61c893a776323211dbc1d3b5d1d10c7d745e.zip
tcl-70ea61c893a776323211dbc1d3b5d1d10c7d745e.tar.gz
tcl-70ea61c893a776323211dbc1d3b5d1d10c7d745e.tar.bz2
[Bug 3466099] BOM in Unicode
Diffstat (limited to 'generic/tclIOUtil.c')
-rw-r--r--generic/tclIOUtil.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c
index b54b76b..5a8d022 100644
--- a/generic/tclIOUtil.c
+++ b/generic/tclIOUtil.c
@@ -1755,11 +1755,25 @@ Tcl_FSEvalFile(interp, pathPtr)
* [Bug: 2040]
*/
Tcl_SetChannelOption(interp, chan, "-eofchar", "\32");
- if (Tcl_ReadChars(chan, objPtr, -1, 0) < 0) {
- Tcl_Close(interp, chan);
+ /* 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), (char *) NULL);
+ 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);
goto end;
}
if (Tcl_Close(interp, chan) != TCL_OK) {