From 53d649dec4c98c9f08b963ed913685a83d68e7e1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 20 Oct 2016 12:11:38 +0200 Subject: Fix testscript here-document quoting issue --- build2/test/script/lexer.cxx | 6 ++++-- build2/test/script/parser.cxx | 3 ++- unit-tests/test/script/parser/command-re-parse.test | 9 +++++++++ unit-tests/test/script/parser/here-document.test | 20 ++++++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 unit-tests/test/script/parser/command-re-parse.test create mode 100644 unit-tests/test/script/parser/here-document.test diff --git a/build2/test/script/lexer.cxx b/build2/test/script/lexer.cxx index f75ad4a..d2657c6 100644 --- a/build2/test/script/lexer.cxx +++ b/build2/test/script/lexer.cxx @@ -20,6 +20,7 @@ namespace build2 const char* s1 (nullptr); const char* s2 (nullptr); bool s (true); + bool q (true); switch (m) { @@ -58,11 +59,12 @@ namespace build2 case lexer_mode::here_line: { // This one is like a double-quoted string except it treats - // newlines as a separator. + // newlines as a separator. We also treat quotes as literals. // s1 = "$(\n"; s2 = " "; s = false; + q = false; break; } default: @@ -74,7 +76,7 @@ namespace build2 } } - state_.push (state {m, '\0', s, s1, s2}); + state_.push (state {m, '\0', s, q, s1, s2}); } token lexer:: diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx index a9a179b..f2f9b81 100644 --- a/build2/test/script/parser.cxx +++ b/build2/test/script/parser.cxx @@ -743,8 +743,9 @@ namespace build2 r += ' '; r += s; - r += '\n'; // Here-document line always includes a newline. } + + r += '\n'; // Here-document line always includes a newline. } // We should expand the whole line at once so this would normally be diff --git a/unit-tests/test/script/parser/command-re-parse.test b/unit-tests/test/script/parser/command-re-parse.test new file mode 100644 index 0000000..956052d --- /dev/null +++ b/unit-tests/test/script/parser/command-re-parse.test @@ -0,0 +1,9 @@ + +# double-quote +# +$* <>EOO +x = cmd \\">!\\" "'!" ">EOO +cmd <