diff options
author | Steve Bennett <steveb@workware.net.au> | 2013-11-11 18:31:53 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2013-11-11 20:40:46 +1000 |
commit | 5a8a3016b9e1218dd6f478259e890510c2a53e3d (patch) | |
tree | a985a6e142ca64e4e9c1733fcd022f715a1736b8 | |
parent | 2dba052c8e456f5d4b1b77fa85f4105650f1fe38 (diff) | |
download | jimtcl-5a8a3016b9e1218dd6f478259e890510c2a53e3d.zip jimtcl-5a8a3016b9e1218dd6f478259e890510c2a53e3d.tar.gz jimtcl-5a8a3016b9e1218dd6f478259e890510c2a53e3d.tar.bz2 |
Properly respect backslashes in comments
Reported-by: Sergei Gavrikov <sergei.gavrikov@gmail.com>
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | jim.c | 22 | ||||
-rw-r--r-- | tests/parse.test | 15 |
2 files changed, 30 insertions, 7 deletions
@@ -1732,7 +1732,6 @@ static int JimParseStr(struct JimParserCtx *pc) else if (pc->len == 1) { /* End of script with trailing backslash */ pc->missing = '\\'; - pc->missingline = pc->tline; } break; case '(': @@ -1794,13 +1793,22 @@ static int JimParseStr(struct JimParserCtx *pc) static int JimParseComment(struct JimParserCtx *pc) { while (*pc->p) { - if (*pc->p == '\n') { + if (*pc->p == '\\') { + pc->p++; + pc->len--; + if (pc->len == 0) { + pc->missing = '\\'; + return JIM_OK; + } + if (*pc->p == '\n') { + pc->linenr++; + } + } + else if (*pc->p == '\n') { + pc->p++; + pc->len--; pc->linenr++; - if (*(pc->p - 1) != '\\') { - pc->p++; - pc->len--; - return JIM_OK; - } + break; } pc->p++; pc->len--; diff --git a/tests/parse.test b/tests/parse.test index e352fc3..982c4a4 100644 --- a/tests/parse.test +++ b/tests/parse.test @@ -320,4 +320,19 @@ test parse-1.63 "unquoted dollar sign" { set x x$ } {x$} +test parse-1.64 "backslash in comment" { + set x 0 + # comment \ + incr x + incr x +} 1 + +test parse-1.65 "double backslash in comment" { + set x 0 + # comment \\ + incr x + incr x +} 2 + + testreport |