diff options
author | raymes <raymes@chromium.org> | 2015-03-31 19:14:36 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-01 02:15:17 +0000 |
commit | 714f45ab973ab09d727dfaed319ef62789ae9393 (patch) | |
tree | 7c5f050e41d91a6ddb79307f43f2e5372174ead6 /tools/gn/value.cc | |
parent | 745f645d044cede33a60e03454bbf797df627cce (diff) | |
download | chromium_src-714f45ab973ab09d727dfaed319ef62789ae9393.zip chromium_src-714f45ab973ab09d727dfaed319ef62789ae9393.tar.gz chromium_src-714f45ab973ab09d727dfaed319ef62789ae9393.tar.bz2 |
Revert of Revert of tools/gn: fix escaping of backslashes (patchset #1 id:1 of https://codereview.chromium.org/1049963002/)
Reason for revert:
Reland as it can't be the cause of the issue.
Original issue's description:
> Revert of tools/gn: fix escaping of backslashes (patchset #3 id:40001 of https://codereview.chromium.org/995393005/)
>
> Reason for revert:
> Speculatively reverting because of: http://build.chromium.org/p/chromium.win/buildstatus?builder=Win8%20GN%20%28dbg%29&number=4637
>
> ERROR at //third_party/WebKit/Source/bindings/scripts/scripts.gni:198:5: Unable to write file.
> write_file(idl_files_list, rebase_path(invoker.sources, root_build_dir))
>
> Original issue's description:
> > tools/gn: fix escaping of backslashes
> >
> > BUG=470217
> >
> > Committed: https://crrev.com/4bf46ca929d17910fcf66cc25e886b986845ca59
> > Cr-Commit-Position: refs/heads/master@{#323161}
>
> TBR=brettw@chromium.org,mdempsky@chromium.org
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=470217
>
> Committed: https://crrev.com/745f645d044cede33a60e03454bbf797df627cce
> Cr-Commit-Position: refs/heads/master@{#323167}
TBR=brettw@chromium.org,mdempsky@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=470217
Review URL: https://codereview.chromium.org/1043383002
Cr-Commit-Position: refs/heads/master@{#323168}
Diffstat (limited to 'tools/gn/value.cc')
-rw-r--r-- | tools/gn/value.cc | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/tools/gn/value.cc b/tools/gn/value.cc index 6dfe234..1a4215c 100644 --- a/tools/gn/value.cc +++ b/tools/gn/value.cc @@ -124,15 +124,27 @@ std::string Value::ToString(bool quote_string) const { return base::Int64ToString(int_value_); case STRING: if (quote_string) { - std::string escaped = string_value_; - // First escape all special uses of a backslash. - ReplaceSubstringsAfterOffset(&escaped, 0, "\\$", "\\\\$"); - ReplaceSubstringsAfterOffset(&escaped, 0, "\\\"", "\\\\\""); - - // Now escape special chars. - ReplaceSubstringsAfterOffset(&escaped, 0, "$", "\\$"); - ReplaceSubstringsAfterOffset(&escaped, 0, "\"", "\\\""); - return "\"" + escaped + "\""; + std::string result = "\""; + bool hanging_backslash = false; + for (char ch : string_value_) { + // If the last character was a literal backslash and the next + // character could form a valid escape sequence, we need to insert + // an extra backslash to prevent that. + if (hanging_backslash && (ch == '$' || ch == '"' || ch == '\\')) + result += '\\'; + // If the next character is a dollar sign or double quote, it needs + // to be escaped; otherwise it can be printed as is. + if (ch == '$' || ch == '"') + result += '\\'; + result += ch; + hanging_backslash = (ch == '\\'); + } + // Again, we need to prevent the closing double quotes from becoming + // an escape sequence. + if (hanging_backslash) + result += '\\'; + result += '"'; + return result; } return string_value_; case LIST: { |