Skip to content

Commit

Permalink
Escape $.
Browse files Browse the repository at this point in the history
  • Loading branch information
dillof committed May 11, 2024
1 parent e36e662 commit 68fecc5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/Word.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/special-characters.test
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 ..
Expand Down

0 comments on commit 68fecc5

Please sign in to comment.