OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/json_parser.h" | 5 #include "base/json/json_parser.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 | 619 |
620 // StringBuilder will internally build a StringPiece unless a UTF-16 | 620 // StringBuilder will internally build a StringPiece unless a UTF-16 |
621 // conversion occurs, at which point it will perform a copy into a | 621 // conversion occurs, at which point it will perform a copy into a |
622 // std::string. | 622 // std::string. |
623 StringBuilder string(NextChar()); | 623 StringBuilder string(NextChar()); |
624 | 624 |
625 int length = end_pos_ - start_pos_; | 625 int length = end_pos_ - start_pos_; |
626 int32_t next_char = 0; | 626 int32_t next_char = 0; |
627 | 627 |
628 while (CanConsume(1)) { | 628 while (CanConsume(1)) { |
629 const int start_index = index_; | |
sky
2016/11/03 19:14:14
It may be possible to backtrack for the first vali
| |
629 pos_ = start_pos_ + index_; // CBU8_NEXT is postcrement. | 630 pos_ = start_pos_ + index_; // CBU8_NEXT is postcrement. |
630 CBU8_NEXT(start_pos_, index_, length, next_char); | 631 CBU8_NEXT(start_pos_, index_, length, next_char); |
631 if (next_char < 0 || !IsValidCharacter(next_char)) { | 632 if (next_char < 0 || !IsValidCharacter(next_char)) { |
632 ReportError(JSONReader::JSON_UNSUPPORTED_ENCODING, 1); | 633 if ((options_ & JSON_ALLOW_NON_UTF_STRINGS) == 0) { |
633 return false; | 634 ReportError(JSONReader::JSON_UNSUPPORTED_ENCODING, 1); |
635 return false; | |
636 } | |
637 string.Convert(); | |
638 std::string invalid_string(index_ - start_index, 0); | |
639 memcpy(&invalid_string.front(), pos_, index_ - start_index); | |
brettw
2016/11/04 23:17:13
Personally, I would prefer substituting it with th
sky
2016/11/08 01:02:20
Done.
| |
640 string.AppendString(invalid_string); | |
641 continue; | |
634 } | 642 } |
635 | 643 |
636 if (next_char == '"') { | 644 if (next_char == '"') { |
637 --index_; // Rewind by one because of CBU8_NEXT. | 645 --index_; // Rewind by one because of CBU8_NEXT. |
638 out->Swap(&string); | 646 out->Swap(&string); |
639 return true; | 647 return true; |
640 } | 648 } |
641 | 649 |
642 // If this character is not an escape sequence... | 650 // If this character is not an escape sequence... |
643 if (next_char != '\\') { | 651 if (next_char != '\\') { |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
979 const std::string& description) { | 987 const std::string& description) { |
980 if (line || column) { | 988 if (line || column) { |
981 return StringPrintf("Line: %i, column: %i, %s", | 989 return StringPrintf("Line: %i, column: %i, %s", |
982 line, column, description.c_str()); | 990 line, column, description.c_str()); |
983 } | 991 } |
984 return description; | 992 return description; |
985 } | 993 } |
986 | 994 |
987 } // namespace internal | 995 } // namespace internal |
988 } // namespace base | 996 } // namespace base |
OLD | NEW |