diff options
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | generic/tclParse.c | 8 | ||||
-rw-r--r-- | tests/parse.test | 12 |
3 files changed, 19 insertions, 3 deletions
@@ -18,6 +18,8 @@ scenario. Simply looking for the braces where they must be is the revision available to those callers, and it will backport cleanly. + * tests/parse.test: Tests for expanded literals quoting detection. + * generic/tclCompCmds.c: New TclFindElement() is also a better fit for the [switch] compiler. diff --git a/generic/tclParse.c b/generic/tclParse.c index c8d2012..96c2a10 100644 --- a/generic/tclParse.c +++ b/generic/tclParse.c @@ -496,6 +496,7 @@ Tcl_ParseCommand( * tokens representing the expanded list. */ + CONST char *listStart; int growthNeeded = wordIndex + 2*elemCount - parsePtr->numTokens; parsePtr->numWords += elemCount - 1; @@ -514,7 +515,7 @@ Tcl_ParseCommand( * word value. */ - nextElem = tokenPtr[1].start; + listStart = nextElem = tokenPtr[1].start; while (nextElem < listEnd) { int quoted; @@ -528,8 +529,9 @@ Tcl_ParseCommand( &(tokenPtr->start), &nextElem, &(tokenPtr->size), NULL); - quoted = tokenPtr->start[-1] == '{' - || tokenPtr->start[-1] == '"'; + quoted = (tokenPtr->start[-1] == '{' + || tokenPtr->start[-1] == '"') + && tokenPtr->start > listStart; tokenPtr[-1].start = tokenPtr->start - quoted; tokenPtr[-1].size = tokenPtr->start + tokenPtr->size - tokenPtr[-1].start + quoted; diff --git a/tests/parse.test b/tests/parse.test index b5211e7..37c44d5 100644 --- a/tests/parse.test +++ b/tests/parse.test @@ -227,6 +227,18 @@ test parse-5.26 {Tcl_ParseCommand: {*} parsing} testparser { test parse-5.27 {Tcl_ParseCommand: {*} parsing} testparser { testparser "{*}\\\n foo bar" 0 } {- \{*\}\\\n\ foo\ bar 3 simple {{*}} 1 text * 0 simple foo 1 text foo 0 simple bar 1 text bar 0 {}} +test parse-5.28 {Tcl_ParseCommand: {*} parsing, expanded literals} testparser { + testparser {{*}{a b}} 0 +} {- {{*}{a b}} 2 simple a 1 text a 0 simple b 1 text b 0 {}} +test parse-5.29 {Tcl_ParseCommand: {*} parsing, expanded literals, naked backslashes} testparser { + testparser {{*}{a \n b}} 0 +} {- {{*}{a \n b}} 1 expand {{*}{a \n b}} 1 text {a \n b} 0 {}} +test parse-5.30 {Tcl_ParseCommand: {*} parsing, expanded literals} testparser { + testparser {{*}"a b"} 0 +} {- {{*}"a b"} 2 simple a 1 text a 0 simple b 1 text b 0 {}} +test parse-5.31 {Tcl_ParseCommand: {*} parsing, expanded literals, naked backslashes} testparser { + testparser {{*}"a \n b"} 0 +} {- {{*}"a \n b"} 1 expand {{*}"a \n b"} 3 text {a } 0 backslash {\n} 0 text { b} 0 {}} test parse-6.1 {ParseTokens procedure, empty word} testparser { testparser {""} 0 |