summaryrefslogtreecommitdiffstats
path: root/generic/tkOption.c
diff options
context:
space:
mode:
authorjan.nijtmans <jan.nijtmans@noemail.net>2015-10-25 22:32:41 (GMT)
committerjan.nijtmans <jan.nijtmans@noemail.net>2015-10-25 22:32:41 (GMT)
commit4b19205e9f80453077be66f11d4f95c7120e19ed (patch)
tree16b5653a385b8259c573d8c1ee9ca6391a10bcf1 /generic/tkOption.c
parentc5052dadf7aca59f23153a6cd6ca2be2e93be51a (diff)
parent02074fadc4f1212236cf1f4525fc45bdc27b1950 (diff)
downloadtk-4b19205e9f80453077be66f11d4f95c7120e19ed.zip
tk-4b19205e9f80453077be66f11d4f95c7120e19ed.tar.gz
tk-4b19205e9f80453077be66f11d4f95c7120e19ed.tar.bz2
Fix [477949]: option readfile cannot use multibytes.
Implementation adopted from AndroWish, but added support for UTF-8 BOM and added test-case. FossilOrigin-Name: 16df5a3ff481aee9ab1aedff07c784c34e324e44
Diffstat (limited to 'generic/tkOption.c')
-rw-r--r--generic/tkOption.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/generic/tkOption.c b/generic/tkOption.c
index 75dc3b9..d758b6f 100644
--- a/generic/tkOption.c
+++ b/generic/tkOption.c
@@ -1083,7 +1083,7 @@ ReadOptionFile(
char *buffer;
int result, bufferSize;
Tcl_Channel chan;
- Tcl_DString newName;
+ Tcl_DString newName, optString;
/*
* Prevent file system access in a safe interpreter.
@@ -1135,7 +1135,16 @@ ReadOptionFile(
}
Tcl_Close(NULL, chan);
buffer[bufferSize] = 0;
- result = AddFromString(interp, tkwin, buffer, priority);
+ if ((bufferSize>2) && !memcmp(buffer, "\357\273\277", 3)) {
+ /* File starts with UTF-8 BOM */
+ result = AddFromString(interp, tkwin, buffer+3, priority);
+ } else {
+ Tcl_DStringInit(&optString);
+ Tcl_ExternalToUtfDString(NULL, buffer, bufferSize, &optString);
+ result = AddFromString(interp, tkwin, Tcl_DStringValue(&optString),
+ priority);
+ Tcl_DStringFree(&optString);
+ }
ckfree(buffer);
return result;
}