Commit c9f5e539 authored by Pavlo Kushnir's avatar Pavlo Kushnir Committed by Sara Golemon

Fix bug in stripComments

Summary: the bug is in InString state when we escape only '"' character. We should escape at least '\\' and '"'. This diffs simply escapes any character after '\\'.

Test Plan: folly unit tests, mcrouter unit tests

Reviewed By: stepan@fb.com

Subscribers: njormrod

FB internal diff: D1540836
parent be42394a
......@@ -705,18 +705,21 @@ fbstring stripComments(StringPiece jsonC) {
state = State::LineComment;
++i;
continue;
} else if (s.startsWith("\"")) {
} else if (s[0] == '\"') {
state = State::InString;
}
result.push_back(s[0]);
break;
case State::InString:
if (s.startsWith("\\\"")) {
if (s[0] == '\\') {
if (UNLIKELY(s.size() == 1)) {
throw std::logic_error("Invalid JSONC: string is not terminated");
}
result.push_back(s[0]);
result.push_back(s[1]);
++i;
continue;
} else if (s.startsWith("\"")) {
} else if (s[0] == '\"') {
state = State::None;
}
result.push_back(s[0]);
......@@ -728,7 +731,7 @@ fbstring stripComments(StringPiece jsonC) {
}
break;
case State::LineComment:
if (s.startsWith("\n")) {
if (s[0] == '\n') {
// skip the line break. It doesn't matter.
state = State::None;
}
......
......@@ -7,5 +7,6 @@
*/
"test4": "foo /* bar", /* comment */
"te//": "foo",
"te/*": "bar"
"te/*": "bar",
"\\\"": "\\" /* comment */
}
......@@ -2,5 +2,6 @@
"test": "foo", "test2": "foo // bar",
"test4": "foo /* bar",
"te//": "foo",
"te/*": "bar"
"te/*": "bar",
"\\\"": "\\"
}
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