Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1738)

Unified Diff: base/json/string_escape.cc

Issue 2903773003: Escape invalid code points (Closed)
Patch Set: Update documentation and signed/unsigned comparison Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/json/string_escape.h ('k') | base/json/string_escape_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/json/string_escape.cc
diff --git a/base/json/string_escape.cc b/base/json/string_escape.cc
index f67fa93bf2648191564eb1a77d46664036b1f41d..9a26ff76c4f4217c8637f2f44babaad0ddc190cd 100644
--- a/base/json/string_escape.cc
+++ b/base/json/string_escape.cc
@@ -91,7 +91,9 @@ bool EscapeJSONStringImpl(const S& str, bool put_in_quotes, std::string* dest) {
for (int32_t i = 0; i < length; ++i) {
uint32_t code_point;
- if (!ReadUnicodeCharacter(str.data(), length, &i, &code_point)) {
+ if (!ReadUnicodeCharacter(str.data(), length, &i, &code_point) ||
+ code_point == static_cast<decltype(code_point)>(CBU_SENTINEL) ||
+ !IsValidCharacter(code_point)) {
code_point = kReplacementCodePoint;
did_replacement = true;
}
« no previous file with comments | « base/json/string_escape.h ('k') | base/json/string_escape_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698