OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |