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

Side by Side Diff: base/json/string_escape.cc

Issue 1325253002: Treat U+2028 as a special code point when escaping for JSON. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: U+2029 Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/json/string_escape_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/json/string_escape.h" 5 #include "base/json/string_escape.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 dest->append("\\\\"); 52 dest->append("\\\\");
53 break; 53 break;
54 case '"': 54 case '"':
55 dest->append("\\\""); 55 dest->append("\\\"");
56 break; 56 break;
57 // Escape < to prevent script execution; escaping > is not necessary and 57 // Escape < to prevent script execution; escaping > is not necessary and
58 // not doing so save a few bytes. 58 // not doing so save a few bytes.
59 case '<': 59 case '<':
60 dest->append("\\u003C"); 60 dest->append("\\u003C");
61 break; 61 break;
62 // Escape the "Line Separator" and "Paragraph Separator" characters, since
63 // they should be treated like a new line \r or \n.
64 case 0x2028:
65 dest->append("\\u2028");
66 break;
67 case 0x2029:
68 dest->append("\\u2029");
69 break;
62 default: 70 default:
63 return false; 71 return false;
64 } 72 }
65 return true; 73 return true;
66 } 74 }
67 75
68 template <typename S> 76 template <typename S>
69 bool EscapeJSONStringImpl(const S& str, bool put_in_quotes, std::string* dest) { 77 bool EscapeJSONStringImpl(const S& str, bool put_in_quotes, std::string* dest) {
70 bool did_replacement = false; 78 bool did_replacement = false;
71 79
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 dest.push_back(*it); 153 dest.push_back(*it);
146 } 154 }
147 155
148 if (put_in_quotes) 156 if (put_in_quotes)
149 dest.push_back('"'); 157 dest.push_back('"');
150 158
151 return dest; 159 return dest;
152 } 160 }
153 161
154 } // namespace base 162 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/json/string_escape_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698