Commit b5f4de91 authored by bgeron's avatar bgeron Committed by Commit bot

[turbolizer] Output correct JSON when source contains a backslash.

Previously, we would output \x5c to escape a backslash, but this is
invalid JSON and it would crash Turbolizer. Use \u005c instead.

BUG=

Review-Url: https://codereview.chromium.org/2224913002
Cr-Commit-Position: refs/heads/master@{#38479}
parent 87448cdd
......@@ -61,6 +61,14 @@ std::ostream& PrintUC16(std::ostream& os, uint16_t c, bool (*pred)(uint16_t)) {
return os << buf;
}
std::ostream& PrintUC16ForJSON(std::ostream& os, uint16_t c,
bool (*pred)(uint16_t)) {
// JSON does not allow \x99; must use \u0099.
char buf[10];
const char* format = pred(c) ? "%c" : "\\u%04x";
snprintf(buf, sizeof(buf), format, c);
return os << buf;
}
std::ostream& PrintUC32(std::ostream& os, int32_t c, bool (*pred)(uint16_t)) {
if (c <= String::kMaxUtf16CodeUnit) {
......@@ -84,7 +92,7 @@ std::ostream& operator<<(std::ostream& os, const AsEscapedUC16ForJSON& c) {
if (c.value == '\r') return os << "\\r";
if (c.value == '\t') return os << "\\t";
if (c.value == '\"') return os << "\\\"";
return PrintUC16(os, c.value, IsOK);
return PrintUC16ForJSON(os, c.value, IsOK);
}
......
......@@ -38,7 +38,7 @@ bytecodes: [
/* 58 S> */ B(Return),
]
constant pool: [
"(\x5cw+)\x5cs(\x5cw+)",
"(\u005cw+)\u005cs(\u005cw+)",
]
handlers: [
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment