From 467977f20326f704b259157652ee9b7ba2efaa78 Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Thu, 2 Jul 2015 23:53:04 +0200 Subject: Fix the parsing of "$"'s in strings. --- src/libexpr/lexer.l | 11 +++++------ tests/lang/eval-okay-string.exp | 2 +- tests/lang/eval-okay-string.nix | 2 ++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index 7483e5cc4acb..1f2957ec71ad 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -129,12 +129,11 @@ or { return OR_KW; } \} { POP_STATE(); return '}'; } \" { PUSH_STATE(STRING); return '"'; } -([^\$\"\\]|\$[^\{\"]|\\.)+ { - /* !!! Not quite right: we want a follow restriction on - "$", it shouldn't be followed by a "{". Right now - "$\"" will be consumed as part of a string, rather - than a "$" followed by the string terminator. - Disallow "$\"" for now. */ +([^\$\"\\]|\$[^\{\"\\]|\\.|\$\\.)*\$/\" | +([^\$\"\\]|\$[^\{\"\\]|\\.|\$\\.)+ { + /* It is impossible to match strings ending with '$' with one + regex because trailing contexts are only valid at the end + of a rule. (A sane but undocumented limitation.) */ yylval->e = unescapeStr(data->symbols, yytext); return STR; } diff --git a/tests/lang/eval-okay-string.exp b/tests/lang/eval-okay-string.exp index 6079202470e3..63f650f73a3a 100644 --- a/tests/lang/eval-okay-string.exp +++ b/tests/lang/eval-okay-string.exp @@ -1 +1 @@ -"foobar/a/b/c/d/foo/xyzzy/foo.txt/../foo/x/yescape: \"quote\" \n \\end\nof\nlinefoobarblaatfoo$bar" +"foobar/a/b/c/d/foo/xyzzy/foo.txt/../foo/x/yescape: \"quote\" \n \\end\nof\nlinefoobarblaatfoo$bar$\"$\"$" diff --git a/tests/lang/eval-okay-string.nix b/tests/lang/eval-okay-string.nix index 839539e6c171..47cc989ad46a 100644 --- a/tests/lang/eval-okay-string.nix +++ b/tests/lang/eval-okay-string.nix @@ -8,3 +8,5 @@ of line" + "foo${if true then "b${"a" + "r"}" else "xyzzy"}blaat" + "foo$bar" + + "$\"$\"" + + "$" -- cgit 1.4.1