summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2015-10-25 22:00:54 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2015-10-25 22:00:54 (GMT)
commit6517ea57da28dce9742a12980122acc1c59a5671 (patch)
tree44adfb486b7d1a745d56daa95b597a89e4b0fb7c
parent4b830288d02e49fa96ed7b5d20bf8170297abcba (diff)
downloadtk-6517ea57da28dce9742a12980122acc1c59a5671.zip
tk-6517ea57da28dce9742a12980122acc1c59a5671.tar.gz
tk-6517ea57da28dce9742a12980122acc1c59a5671.tar.bz2
Fix [477949]: option readfile cannot use multibytes.
Implementation adopted from AndroWish, but added support for UTF-8 BOM and added test-case.
-rw-r--r--generic/tkOption.c13
-rwxr-xr-xtests/option.file318
-rw-r--r--tests/option.test11
3 files changed, 36 insertions, 6 deletions
diff --git a/generic/tkOption.c b/generic/tkOption.c
index 91a6cc0..bff799b 100644
--- a/generic/tkOption.c
+++ b/generic/tkOption.c
@@ -1086,7 +1086,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.
@@ -1136,7 +1136,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;
}
diff --git a/tests/option.file3 b/tests/option.file3
new file mode 100755
index 0000000..87f41ae
--- /dev/null
+++ b/tests/option.file3
@@ -0,0 +1,18 @@
+! This file is a sample option (resource) database used to test
+! Tk's option-handling capabilities.
+
+! Comment line \
+ with a backslash-newline sequence embedded in it.
+
+*x1: blue
+ tktest.x2 : green
+*\
+x3 \
+ : pur\
+ple
+*x 4: brówn
+# More comments, this time delimited by hash-marks.
+ # Comment-line with space.
+*x6:
+*x9: \ \ \\\101\n
+# comment line as last line of file.
diff --git a/tests/option.test b/tests/option.test
index 1bfcb7c..4668771 100644
--- a/tests/option.test
+++ b/tests/option.test
@@ -187,6 +187,7 @@ test option-14.12 {error conditions} {
set option1 [file join [testsDirectory] option.file1]
set option2 [file join [testsDirectory] option.file2]
+set option3 [file join [testsDirectory] option.file3]
test option-15.1 {database files} {
list [catch {option read non-existent} msg] $msg
@@ -207,16 +208,18 @@ test option-15.9 {database files} {option get . x3 color} burgundy
test option-15.10 {database files} {
list [catch {option read $option2} msg] $msg
} {1 {missing colon on line 2}}
+option read $option3
+test option-15.11 {database files} {option get . {x 4} color} br\xf3wn
test option-16.1 {ReadOptionFile} {
- set option3 [makeFile {} option.file3]
- set file [open $option3 w]
+ set option4 [makeFile {} option.file3]
+ set file [open $option4 w]
fconfigure $file -translation crlf
puts $file "*x7: true\n*x8: false"
close $file
- option read $option3 userDefault
+ option read $option4 userDefault
set result [list [option get . x7 color] [option get . x8 color]]
- removeFile $option3
+ removeFile $option4
set result
} {true false}