| 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_reader.h" | 5 #include "base/json_reader.h" |
| 6 | 6 |
| 7 #include "base/float_util.h" | 7 #include "base/float_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 Value** root, | 76 Value** root, |
| 77 bool allow_trailing_comma) { | 77 bool allow_trailing_comma) { |
| 78 return JsonToValue(json, root, true, allow_trailing_comma); | 78 return JsonToValue(json, root, true, allow_trailing_comma); |
| 79 } | 79 } |
| 80 | 80 |
| 81 /* static */ | 81 /* static */ |
| 82 bool JSONReader::JsonToValue(const std::string& json, | 82 bool JSONReader::JsonToValue(const std::string& json, |
| 83 Value** root, | 83 Value** root, |
| 84 bool check_root, | 84 bool check_root, |
| 85 bool allow_trailing_comma) { | 85 bool allow_trailing_comma) { |
| 86 // Assume input is UTF8. The conversion from UTF8 to wstring removes null | 86 // The input must be in UTF-8. |
| 87 // bytes for us (a good thing). | 87 if (!IsStringUTF8(json.c_str())) |
| 88 return false; |
| 89 // The conversion from UTF8 to wstring removes null bytes for us |
| 90 // (a good thing). |
| 88 std::wstring json_wide(UTF8ToWide(json)); | 91 std::wstring json_wide(UTF8ToWide(json)); |
| 89 const wchar_t* json_cstr = json_wide.c_str(); | 92 const wchar_t* json_cstr = json_wide.c_str(); |
| 90 | 93 |
| 91 // When the input JSON string starts with a UTF-8 Byte-Order-Mark | 94 // When the input JSON string starts with a UTF-8 Byte-Order-Mark |
| 92 // (0xEF, 0xBB, 0xBF), the UTF8ToWide() function converts it to a Unicode | 95 // (0xEF, 0xBB, 0xBF), the UTF8ToWide() function converts it to a Unicode |
| 93 // BOM (U+FEFF). To avoid the JSONReader::BuildValue() function from | 96 // BOM (U+FEFF). To avoid the JSONReader::BuildValue() function from |
| 94 // mis-treating a Unicode BOM as an invalid character and returning false, | 97 // mis-treating a Unicode BOM as an invalid character and returning false, |
| 95 // skip a converted Unicode BOM if it exists. | 98 // skip a converted Unicode BOM if it exists. |
| 96 if (!json_wide.empty() && json_cstr[0] == 0xFEFF) { | 99 if (!json_wide.empty() && json_cstr[0] == 0xFEFF) { |
| 97 ++json_cstr; | 100 ++json_cstr; |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 default: | 571 default: |
| 569 ++json_pos_; | 572 ++json_pos_; |
| 570 } | 573 } |
| 571 } | 574 } |
| 572 } else { | 575 } else { |
| 573 return false; | 576 return false; |
| 574 } | 577 } |
| 575 return true; | 578 return true; |
| 576 } | 579 } |
| 577 | 580 |
| OLD | NEW |