aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2010-10-05 13:16:25 +1000
committerSteve Bennett <steveb@workware.net.au>2010-10-15 11:02:58 +1000
commit352d450a94f89b4415c4d3ee56664d9815389b94 (patch)
tree9494757bb04e57df001e6cc09f27af1a9e4f13c4
parent22fc43c8dbca0205c854ae6e1c7f2c9c3c354125 (diff)
downloadjimtcl-352d450a94f89b4415c4d3ee56664d9815389b94.zip
jimtcl-352d450a94f89b4415c4d3ee56664d9815389b94.tar.gz
jimtcl-352d450a94f89b4415c4d3ee56664d9815389b94.tar.bz2
Fix a concat bug
If a string ended in backslash-space, the trailing space was lost. Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--jim.c8
-rw-r--r--tests/concat.test32
2 files changed, 39 insertions, 1 deletions
diff --git a/jim.c b/jim.c
index 0ed2c03..41f7666 100644
--- a/jim.c
+++ b/jim.c
@@ -5954,18 +5954,24 @@ Jim_Obj *Jim_ConcatObj(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
}
if (objc)
len += objc - 1;
- /* Create the string rep, and a stinrg object holding it. */
+ /* Create the string rep, and a string object holding it. */
p = bytes = Jim_Alloc(len + 1);
for (i = 0; i < objc; i++) {
const char *s = Jim_GetString(objv[i], &objLen);
+ /* Remove leading space */
while (objLen && (*s == ' ' || *s == '\t' || *s == '\n')) {
s++;
objLen--;
len--;
}
+ /* And trailing space */
while (objLen && (s[objLen - 1] == ' ' ||
s[objLen - 1] == '\n' || s[objLen - 1] == '\t')) {
+ /* Handle trailing backslash-space case */
+ if (objLen > 1 && s[objLen - 2] == '\\') {
+ break;
+ }
objLen--;
len--;
}
diff --git a/tests/concat.test b/tests/concat.test
index 65d6e1b..7f961a8 100644
--- a/tests/concat.test
+++ b/tests/concat.test
@@ -30,3 +30,35 @@ test concat-4.2 {pruning off extra white space} {
test concat-4.3 {pruning off extra white space sets length correctly} {
llength [concat { {{a}} }]
} 1
+
+test concat-5.1 {Tcl_ScanCountedElement procedure - don't leave unmatched braces} {
+ # This test checks for a very tricky feature. Any list element
+ # generated with Tcl_ScanCountedElement and Tcl_ConvertElement must
+ # have the property that it can be enclosing in curly braces to make
+ # an embedded sub-list. If this property doesn't hold, then
+ # Tcl_DStringStartSublist doesn't work.
+
+ set x {}
+ lappend x " \\\{ \\"
+ concat $x [llength "{$x}"]
+} {\ \\\{\ \\ 1}
+
+test concat-6.1 {Tcl_ConcatObj - backslash-space at end of argument} {
+ concat a {b\ } c
+} {a b\ c}
+test concat-6.2 {Tcl_ConcatObj - backslash-space at end of argument} {
+ concat a {b\ } c
+} {a b\ c}
+test concat-6.3 {Tcl_ConcatObj - backslash-space at end of argument} {
+ concat a {b\\ } c
+} {a b\\ c}
+test concat-6.4 {Tcl_ConcatObj - backslash-space at end of argument} {
+ concat a {b } c
+} {a b c}
+test concat-6.5 {Tcl_ConcatObj - backslash-space at end of argument} {
+ concat a { } c
+} {a c}
+test concat-6.6 {Tcl_ConcatObj - utf-8 sequence with "whitespace" char} {
+ # Check for Bug #227512. If this violates C isspace, then it returns \xc3.
+ concat \xe0
+} \xe0