Revert "Use JSON escaping for JSON string output" This reverts commit afd24ed11bc5fbef775a3ffe46c72e6bdca0fa60. Reason for revert: Broke GN autoroller in chromium. https://crrev.com/c/6604789 Bug: 421876648 Original change's description: > Use JSON escaping for JSON string output > > The previous code used Value::ToString to convert GN strings into quoted > JSON strings, but this caused incorrect escaping behavior. For example, > the string "$" needs to be escaped in Ninja to prevent accidental > variable expansion but not in JSON. > > Change-Id: I91c8e9b2486a67af5a3ba41efdb731aa31cc6df3 > Reviewed-on: https://gn-review.googlesource.com/c/gn/+/18900 > Commit-Queue: Takuto Ikuta <tikuta@google.com> > Reviewed-by: Takuto Ikuta <tikuta@google.com> # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: I88d648e62a4659256d88c5709529005ceedd2558 Reviewed-on: https://gn-review.googlesource.com/c/gn/+/18940 Commit-Queue: David Turner <digit@google.com> Reviewed-by: David Turner <digit@google.com>
diff --git a/src/gn/output_conversion.cc b/src/gn/output_conversion.cc index 3bfbb10..971e740 100644 --- a/src/gn/output_conversion.cc +++ b/src/gn/output_conversion.cc
@@ -4,7 +4,6 @@ #include "gn/output_conversion.h" -#include "gn/escape.h" #include "gn/settings.h" #include "gn/value.h" @@ -38,10 +37,8 @@ RenderScopeToJSON(value, out, indent + 1); else if (value.type() == Value::LIST) RenderListToJSON(value, out, indent + 1); - else if (value.type() == Value::STRING) - EscapeJSONStringToStream(out, value.ToString(false), EscapeOptions()); else - out << value.ToString(false); + out << value.ToString(true); first = false; } out << "\n"; @@ -64,11 +61,8 @@ RenderScopeToJSON(pair.second, out, indent + 1); else if (pair.second.type() == Value::LIST) RenderListToJSON(pair.second, out, indent + 1); - else if (pair.second.type() == Value::STRING) - EscapeJSONStringToStream(out, pair.second.ToString(false), - EscapeOptions()); else - out << pair.second.ToString(false); + out << pair.second.ToString(true); first = false; } out << "\n";
diff --git a/src/gn/output_conversion_unittest.cc b/src/gn/output_conversion_unittest.cc index 1eaf2ab..43fdad5 100644 --- a/src/gn/output_conversion_unittest.cc +++ b/src/gn/output_conversion_unittest.cc
@@ -186,11 +186,8 @@ auto c_scope = std::make_unique<Scope>(settings()); Value e_value(nullptr, Value::LIST); e_value.list_value().push_back(Value(nullptr, "bar")); - e_value.list_value().push_back(Value(nullptr, "$")); auto e_value_scope = std::make_unique<Scope>(settings()); - Value d_value(nullptr, "$"); - e_value_scope->SetValue("d", d_value, nullptr); Value f_value(nullptr, "baz"); e_value_scope->SetValue("f", f_value, nullptr); e_value.list_value().push_back(Value(nullptr, std::move(e_value_scope))); @@ -205,9 +202,7 @@ "c": { "e": [ "bar", - "$", { - "d": "$", "f": "baz" } ]