Skip to content

Commit 7409733

Browse files
author
jan.nijtmans
committed
Fix [e38dce74e2]: Command line built with list not properly quoted
2 parents b1f42b4 + b0b683b commit 7409733

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

generic/tclListObj.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,16 @@ Tcl_ListObjAppendList(
17761776
}
17771777

17781778
if (elemCount <= 0) {
1779+
/*
1780+
* Note that when elemCount <= 0, this routine is logically a
1781+
* no-op, removing and adding no elements to the list. However, by removing
1782+
* the string representation, we get the important side effect that the
1783+
* resulting listPtr is a list in canonical form. This is important.
1784+
* Resist any temptation to optimize this case further. See bug [e38dce74e2].
1785+
*/
1786+
if (!ListObjIsCanonical(toObj)) {
1787+
TclInvalidateStringRep(toObj);
1788+
}
17791789
/* Nothing to do. Note AFTER check for list above */
17801790
return TCL_OK;
17811791
}

tests/list.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ test list-1.30 {basic null treatment} {
6464
set e "\x00abc xyz"
6565
string equal $l $e
6666
} 1
67+
test list-1.31 {bug [e38dce74e2]} {
68+
set l #foo
69+
set e {}
70+
list {*}$l {*}$e
71+
} {{#foo}}
72+
test list-1.32 {bug [e38dce74e2]} {
73+
set l " #foo"
74+
set e {}
75+
list {*}$l {*}$e
76+
} {{#foo}}
6777

6878
# For the next round of tests create a list and then pick it apart
6979
# with "index" to make sure that we get back exactly what went in.

0 commit comments

Comments
 (0)