diff options
-rw-r--r-- | ninjabackend.py | 11 | ||||
-rw-r--r-- | test cases/common/104 backslash/comparer.c | 10 | ||||
-rw-r--r-- | test cases/common/104 backslash/meson.build | 3 |
3 files changed, 18 insertions, 6 deletions
diff --git a/ninjabackend.py b/ninjabackend.py index 1ef2642..8eef148 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 0000000..f562f5e --- /dev/null +++ b/test cases/common/104 backslash/comparer.c @@ -0,0 +1,10 @@ +#include<string.h> +#include<stdio.h> + +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 0000000..dba891e --- /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"')) |