From 98a33759ddfe166ac684db4f4e1d0e174c89d2b5 Mon Sep 17 00:00:00 2001 From: Nicholas Hutchinson Date: Thu, 9 Jan 2014 09:38:20 +1300 Subject: =?UTF-8?q?Don=E2=80=99t=20unnecessarily=20escape=20backslashes=20?= =?UTF-8?q?in=20Win32=20paths?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/util.cc | 1 - src/util_test.cc | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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); -- cgit v0.12