summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoravl <avl>2017-03-05 19:38:43 (GMT)
committeravl <avl>2017-03-05 19:38:43 (GMT)
commit465ee21b4398dd928e24e7241f4ebf0be3601df7 (patch)
tree0574472bdfe596237867ca6a3b3f51cbdd546f7f
parentca4151477f00d6c5aa468ada3361a8cf76208eaa (diff)
downloadtcl-tip_465.zip
tcl-tip_465.tar.gz
tcl-tip_465.tar.bz2
Deal with backslashes in ${...}, change "char" to "character" in error, fix tests.tip_465
-rw-r--r--generic/tclParse.c18
-rw-r--r--tests/parse.test6
-rw-r--r--tests/parseExpr.test4
3 files changed, 18 insertions, 10 deletions
diff --git a/generic/tclParse.c b/generic/tclParse.c
index 10f016d..372ec92 100644
--- a/generic/tclParse.c
+++ b/generic/tclParse.c
@@ -1366,7 +1366,7 @@ Tcl_ParseVarName(
{
Tcl_Token *tokenPtr;
register const char *src;
- int varIndex, braceCount = 0;
+ int varIndex;
unsigned array;
if ((numBytes == 0) || (start == NULL)) {
@@ -1419,7 +1419,7 @@ Tcl_ParseVarName(
*/
if (*src == '{') {
- char ch;
+ char ch; int braceCount = 0;
src++;
numBytes--;
tokenPtr->type = TCL_TOKEN_TEXT;
@@ -1428,8 +1428,16 @@ Tcl_ParseVarName(
ch = *src;
while (numBytes && (braceCount>0 || ch != '}')) {
- if (ch == '{') { braceCount++; }
- else if (ch == '}') { braceCount--; }
+ switch (ch) {
+ case '{': braceCount++; break;
+ case '}': braceCount--; break;
+ case '\\':
+ /* if 2 or more left, consume 2, else consume
+ just the \ and let it run into the end */
+ if (numBytes > 1) {
+ src++; numBytes--;
+ }
+ }
numBytes--;
src++;
ch= *src;
@@ -1504,7 +1512,7 @@ Tcl_ParseVarName(
} else if ((*parsePtr->term != ')')){
if (parsePtr->interp != NULL) {
Tcl_SetObjResult(parsePtr->interp, Tcl_NewStringObj(
- "invalid char in array index", -1));
+ "invalid character in array index", -1));
}
parsePtr->errorType = TCL_PARSE_SYNTAX;
parsePtr->term = src;
diff --git a/tests/parse.test b/tests/parse.test
index 287c392..e031327 100644
--- a/tests/parse.test
+++ b/tests/parse.test
@@ -601,8 +601,8 @@ test parse-12.6 {Tcl_ParseVarName procedure, braced variable name} testparser {
testparser {${..[]b}cd} 0
} {- {${..[]b}cd} 1 word {${..[]b}cd} 3 variable {${..[]b}} 1 text {..[]b} 0 text cd 0 {}}
test parse-12.7 {Tcl_ParseVarName procedure, braced variable name} testparser {
- testparser "\$\{\{\} " 0
-} {- \$\{\{\}\ 1 word \$\{\{\} 2 variable \$\{\{\} 1 text \{ 0 {}}
+ testparser "\$\{\{\\\\\}\} " 0
+} {- {${{\\}} } 1 word {${{\\}}} 2 variable {${{\\}}} 1 text {{\\}} 0 {}}
test parse-12.8 {Tcl_ParseVarName procedure, missing close brace} testparser {
list [catch {testparser "$\{abc" 0} msg] $msg $::errorInfo
} {1 {missing close-brace for variable name} missing\ close-brace\ for\ variable\ name\n\ \ \ \ (remainder\ of\ script:\ \"\{abc\")\n\ \ \ \ invoked\ from\ within\n\"testparser\ \"\$\\\{abc\"\ 0\"}
@@ -797,7 +797,7 @@ test parse-15.16 {CommandComplete procedure} {
} 1
test parse-15.17 {CommandComplete procedure} {
info complete {a b "c $dd("}
-} 0
+} 1
test parse-15.18 {CommandComplete procedure} {
info complete {a b "c \"}
} 0
diff --git a/tests/parseExpr.test b/tests/parseExpr.test
index 47dbec5..e0c979c 100644
--- a/tests/parseExpr.test
+++ b/tests/parseExpr.test
@@ -917,8 +917,8 @@ test parseExpr-21.43 {error message} -body {
in expression \"...8901234567890*\"foobar\$\{abcdefghijklmnopqrstuv...\""
test parseExpr-21.44 {error message} -body {
expr {123456789012345678901234567890*"foo$bar(abcdefghijklmnopqrstuvwxyz"}
-} -returnCodes error -result {missing )
-in expression "...8901234567890*"foo$bar(abcdefghijklmnopqrstuv..."}
+} -returnCodes error -result {invalid character in array index
+in expression "...8901234567890*"foo$bar(abcdefghijklmnopqrstu..."}
test parseExpr-21.45 {error message} -body {
expr {123456789012345678901234567890*"foo$bar([{}abcdefghijklmnopqrstuvwxyz])"}
} -returnCodes error -result {extra characters after close-brace