| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/safe_json/json_sanitizer.h" | 5 #include "components/safe_json/json_sanitizer.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // JSON syntax errors: | 126 // JSON syntax errors: |
| 127 CheckError(""); | 127 CheckError(""); |
| 128 CheckError("["); | 128 CheckError("["); |
| 129 CheckError("null"); | 129 CheckError("null"); |
| 130 | 130 |
| 131 // Unterminated array. | 131 // Unterminated array. |
| 132 CheckError("[1,2,3,]"); | 132 CheckError("[1,2,3,]"); |
| 133 } | 133 } |
| 134 | 134 |
| 135 TEST_F(JsonSanitizerTest, Nesting) { | 135 TEST_F(JsonSanitizerTest, Nesting) { |
| 136 // 99 nested arrays are fine. | 136 // 199 nested arrays are fine. |
| 137 std::string nested(99u, '['); | 137 std::string nested(199u, '['); |
| 138 nested.append(99u, ']'); | 138 nested.append(199u, ']'); |
| 139 CheckSuccess(nested); | 139 CheckSuccess(nested); |
| 140 | 140 |
| 141 // 100 nested arrays is too much. | 141 // 200 nested arrays is too much. |
| 142 CheckError(std::string(100u, '[') + std::string(100u, ']')); | 142 CheckError(std::string(200u, '[') + std::string(200u, ']')); |
| 143 } | 143 } |
| 144 | 144 |
| 145 TEST_F(JsonSanitizerTest, Unicode) { | 145 TEST_F(JsonSanitizerTest, Unicode) { |
| 146 // Non-ASCII characters encoded either directly as UTF-8 or escaped as UTF-16: | 146 // Non-ASCII characters encoded either directly as UTF-8 or escaped as UTF-16: |
| 147 CheckSuccess("[\"☃\"]"); | 147 CheckSuccess("[\"☃\"]"); |
| 148 CheckSuccess("[\"\\u2603\"]"); | 148 CheckSuccess("[\"\\u2603\"]"); |
| 149 CheckSuccess("[\"😃\"]"); | 149 CheckSuccess("[\"😃\"]"); |
| 150 CheckSuccess("[\"\\ud83d\\ude03\"]"); | 150 CheckSuccess("[\"\\ud83d\\ude03\"]"); |
| 151 | 151 |
| 152 // Malformed UTF-8: | 152 // Malformed UTF-8: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 178 // A low surrogate followed by a high surrogate. | 178 // A low surrogate followed by a high surrogate. |
| 179 CheckError("[\"\\ude03\\ud83d\"]"); | 179 CheckError("[\"\\ude03\\ud83d\"]"); |
| 180 | 180 |
| 181 // Valid escaped UTF-16 that encodes non-characters: | 181 // Valid escaped UTF-16 that encodes non-characters: |
| 182 CheckError("[\"\\ufdd0\"]"); | 182 CheckError("[\"\\ufdd0\"]"); |
| 183 CheckError("[\"\\ufffe\"]"); | 183 CheckError("[\"\\ufffe\"]"); |
| 184 CheckError("[\"\\ud83f\\udffe\"]"); | 184 CheckError("[\"\\ud83f\\udffe\"]"); |
| 185 } | 185 } |
| 186 | 186 |
| 187 } // namespace safe_json | 187 } // namespace safe_json |
| OLD | NEW |