diff options
author | Nicholas Hutchinson <nshutchinson@gmail.com> | 2014-01-08 20:38:20 (GMT) |
---|---|---|
committer | Nicholas Hutchinson <nshutchinson@gmail.com> | 2014-01-08 20:38:20 (GMT) |
commit | 98a33759ddfe166ac684db4f4e1d0e174c89d2b5 (patch) | |
tree | 10a824abeb10fdc29c252f4f17ef2efd8ba79197 /src | |
parent | 3e4bf25c40450393b5c5006c11d6e4236294c804 (diff) | |
download | Ninja-98a33759ddfe166ac684db4f4e1d0e174c89d2b5.zip Ninja-98a33759ddfe166ac684db4f4e1d0e174c89d2b5.tar.gz Ninja-98a33759ddfe166ac684db4f4e1d0e174c89d2b5.tar.bz2 |
Don’t unnecessarily escape backslashes in Win32 paths
Under ::CommandLineToArgvW() rules, the backslash character only gets special treatment if it’s immediately followed by a double quote. So, when checking to see if a string needs Win32 escaping, it’s sufficient to check for the presence of a double quote character. This allows paths like "foo\bar" to be recognised as “sensible” paths, which don’t require the full escaping.
Diffstat (limited to 'src')
-rw-r--r-- | src/util.cc | 1 | ||||
-rw-r--r-- | src/util_test.cc | 8 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/util.cc b/src/util.cc index 0e4dc59..24d231f 100644 --- a/src/util.cc +++ b/src/util.cc @@ -194,7 +194,6 @@ static inline bool IsKnownShellSafeCharacter(char ch) { static inline bool IsKnownWin32SafeCharacter(char ch) { switch (ch) { - case '\\': case ' ': case '"': return false; diff --git a/src/util_test.cc b/src/util_test.cc index f6728fb..f827e5a 100644 --- a/src/util_test.cc +++ b/src/util_test.cc @@ -159,6 +159,14 @@ TEST(PathEscaping, SensiblePathsAreNotNeedlesslyEscaped) { EXPECT_EQ(path, result); } +TEST(PathEscaping, SensibleWin32PathsAreNotNeedlesslyEscaped) { + const char* path = "some\\sensible\\path\\without\\crazy\\characters.cc"; + string result; + + GetWin32EscapedString(path, &result); + EXPECT_EQ(path, result); +} + TEST(StripAnsiEscapeCodes, EscapeAtEnd) { string stripped = StripAnsiEscapeCodes("foo\33"); EXPECT_EQ("foo", stripped); |