diff --git a/src/Word.cc b/src/Word.cc index 8fd417a..90d2d34 100644 --- a/src/Word.cc +++ b/src/Word.cc @@ -169,14 +169,15 @@ std::ostream& operator<<(std::ostream& stream, const Word& word) { } std::string Word::StringElement::string() const { - if (!escape || text.find(' ') == std::string::npos) { + if (!escape || text.find_first_of(" $") == std::string::npos) { return text; } std::string escaped; for (char c : text) { - if (c == ' ') { - escaped += "$ "; + if (c == ' ' || c == '$') { + escaped += "$"; + escaped += c; } else { escaped += c; diff --git a/tests/special-characters.test b/tests/special-characters.test index bdc00b9..a14650d 100644 --- a/tests/special-characters.test +++ b/tests/special-characters.test @@ -1,7 +1,7 @@ arguments .. file build.fninja <> rule a - command = a rule build = "a$ b" |@ || | @ + command = a rule build = "a$ b" |@ || | @ $$ end-of-inline-data file build/build.ninja {} <> # This file is automatically created by fast-ninja from ../build.fninja @@ -13,7 +13,7 @@ top_build_directory = . top_source_directory = .. rule a - command = a rule build = "a$ b" |@ || | @ + command = a rule build = "a$ b" |@ || | @ $$ rule fast-ninja command = fast-ninja ..