From f1bf87ec8a765801b8aec97d64e97b578817430b Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 2 Jan 2016 19:14:13 +0200 Subject: [PATCH] Added test to check that backslashes are passed properly through the pipeline. --- ninjabackend.py | 11 +++++------ test cases/common/104 backslash/comparer.c | 10 ++++++++++ test cases/common/104 backslash/meson.build | 3 +++ 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 test cases/common/104 backslash/comparer.c create mode 100644 test cases/common/104 backslash/meson.build diff --git a/ninjabackend.py b/ninjabackend.py index 1ef264272..8eef148f9 100644 --- a/ninjabackend.py +++ b/ninjabackend.py @@ -86,11 +86,10 @@ class NinjaBuildElement(): if len(self.orderdeps) > 0: line += ' || ' + ' '.join([ninja_quote(x) for x in self.orderdeps]) line += '\n' - # This needs to be done to make these strings - # pass through arbitrary shells. Backslash is a - # quote character so it can break at any time. - # Because of this always use forward slashes, - # it is a path separator even on Windows. + # This is the only way I could find to make this work on all + # platforms including Windows command shell. Slash is a dir separator + # on Windows, too, so all characters are unambiguous and, more importantly, + # do not require quoting. line = line.replace('\\', '/') outfile.write(line) @@ -111,7 +110,7 @@ class NinjaBuildElement(): newelems.append(templ % ninja_quote(i)) line += ' '.join(newelems) line += '\n' - line = line.replace('\\', '/') + line = line.replace('\\', '\\\\') outfile.write(line) outfile.write('\n') diff --git a/test cases/common/104 backslash/comparer.c b/test cases/common/104 backslash/comparer.c new file mode 100644 index 000000000..f562f5e37 --- /dev/null +++ b/test cases/common/104 backslash/comparer.c @@ -0,0 +1,10 @@ +#include +#include + +int main(int argc, char **argv) { + if(strcmp(DEF_WITH_BACKSLASH, "foo\\bar")) { + printf("Arg string is quoted incorrectly: %s\n", DEF_WITH_BACKSLASH); + return 1; + } + return 0; +} diff --git a/test cases/common/104 backslash/meson.build b/test cases/common/104 backslash/meson.build new file mode 100644 index 000000000..dba891eea --- /dev/null +++ b/test cases/common/104 backslash/meson.build @@ -0,0 +1,3 @@ +project('comparer', 'c') + +test('backslash quoting', executable('comparer', 'comparer.c', c_args : '-DDEF_WITH_BACKSLASH="foo\\bar"'))