diff options
author | Steve Bennett <steveb@workware.net.au> | 2011-05-31 18:34:48 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2011-05-31 18:34:48 +1000 |
commit | 878a8fdb576ab96d6e8c497e4dffedf82a9afbcf (patch) | |
tree | 137f651cb7f74696153cdf8471b2642c9a722e00 | |
parent | c09f838395bcc33cae854be44a2be5020fb45f87 (diff) | |
download | jimtcl-878a8fdb576ab96d6e8c497e4dffedf82a9afbcf.zip jimtcl-878a8fdb576ab96d6e8c497e4dffedf82a9afbcf.tar.gz jimtcl-878a8fdb576ab96d6e8c497e4dffedf82a9afbcf.tar.bz2 |
Fix a dict sugar parse bug with backslashed chars
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | jim.c | 22 | ||||
-rw-r--r-- | tests/parse.test | 50 |
2 files changed, 64 insertions, 8 deletions
@@ -1339,28 +1339,34 @@ static int JimParseVar(struct JimParserCtx *pc) /* Parse [dict get] syntax sugar. */ if (*pc->p == '(') { int count = 1; + const char *paren = NULL; while (count && pc->len) { pc->p++; pc->len--; - if (*pc->p == '\\' && pc->len >= 2) { - pc->p += 2; - pc->len -= 2; + if (*pc->p == '\\' && pc->len >= 1) { + pc->p++; + pc->len--; } else if (*pc->p == '(') { count++; } else if (*pc->p == ')') { + paren = pc->p; count--; } } - ttype = (*pc->tstart == '(') ? JIM_TT_EXPRSUGAR : JIM_TT_DICTSUGAR; if (count == 0) { - if (*pc->p != '\0') { - pc->p++; - pc->len--; - } + pc->p++; + pc->len--; } + else if (paren) { + /* Did not find a matching paren. Back up */ + paren++; + pc->len += (pc->p - paren); + pc->p = paren; + } + ttype = (*pc->tstart == '(') ? JIM_TT_EXPRSUGAR : JIM_TT_DICTSUGAR; } pc->tend = pc->p - 1; } diff --git a/tests/parse.test b/tests/parse.test index 870d4ff..d8e6035 100644 --- a/tests/parse.test +++ b/tests/parse.test @@ -256,4 +256,54 @@ test parse-1.50 "backslash newline in quotes" { def" } "abc def" +test parse-1.51 "special chars in dict sugar" { + unset -nocomplain a + set a(x$) 5 + array names a +} {{x$}} + +test parse-1.52 "special chars in dict sugar" { + set x $a(x$) +} 5 + +test parse-1.53 "special chars in dict sugar" { + unset -nocomplain a + set a(x\[) 5 + array names a +} {{x[}} + +test parse-1.52 "special chars in dict sugar" { + set x $a(x\[) +} 5 + +test parse-1.53 "special chars in dict sugar" { + unset -nocomplain a + set a(x\() 5 + array names a +} {x(} + +test parse-1.52 "special chars in dict sugar" { + set x $a(x\() +} 5 + +test parse-1.53 "special chars in dict sugar" { + unset -nocomplain a + set a(x() 5 + array names a +} {x(} + +test parse-1.52 "special chars in dict sugar" { + set x $a(x() +} 5 + +test parse-1.53 "special chars in dict sugar" { + unset -nocomplain a + set a(x") 5 + lindex [array names a] 0 +} {x"} + +test parse-1.52 "special chars in dict sugar" { + set x $a(x") +} 5 + testreport |