From e3ce9cc60846cc2e4e4775f6d24c28089bad30ff Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 7 Nov 2016 10:52:01 +0200 Subject: Only do effective escaping when re-parsing expansions in testscript Doing unconditional escaping messes up expansions that are Windows paths. --- build2/test/script/parser.cxx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'build2/test/script/parser.cxx') diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx index df1cd9f..0cc54f7 100644 --- a/build2/test/script/parser.cxx +++ b/build2/test/script/parser.cxx @@ -1595,7 +1595,7 @@ namespace build2 // interesting characters (operators plus quotes/escapes), // then no need to re-lex. // - // NOTE: updated quoting (script.cxx:to_stream_q()) if adding + // NOTE: update quoting (script.cxx:to_stream_q()) if adding // any new characters. // if (q || s.find_first_of ("|&<>\'\"\\") == string::npos) @@ -1631,8 +1631,20 @@ namespace build2 name = path (move (n)); } + // When re-parsing we do "effective escaping" and only for + // ['"\] (quotes plus the backslash itself). In particular, + // there is no way to escape redirects, operators, etc. The + // idea is to prefer quoting except for passing literal + // quotes, for example: + // + // args = \"&foo\" + // cmd $args # cmd &foo + // + // args = 'x=\"foo bar\"' + // cmd $args # cmd x="foo bar" + // istringstream is (s); - lexer lex (is, name, lexer_mode::command_line); + lexer lex (is, name, lexer_mode::command_line, "\'\"\\"); // Treat the first "sub-token" as always separated from what // we saw earlier. -- cgit v1.1