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

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

Issue 9860035: Fix handling of Unicode BOMs in JSONReader. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge origin/master Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « base/base.gyp ('k') | base/json/json_reader_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) 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_reader.h" 5 #include "base/json/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/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 return NULL; 156 return NULL;
157 } 157 }
158 158
159 start_pos_ = json.data(); 159 start_pos_ = json.data();
160 end_pos_ = start_pos_ + json.size(); 160 end_pos_ = start_pos_ + json.size();
161 161
162 // When the input JSON string starts with a UTF-8 Byte-Order-Mark (U+FEFF) 162 // When the input JSON string starts with a UTF-8 Byte-Order-Mark (U+FEFF)
163 // or <0xEF 0xBB 0xBF>, advance the start position to avoid the 163 // or <0xEF 0xBB 0xBF>, advance the start position to avoid the
164 // JSONReader::BuildValue() function from mis-treating a Unicode BOM as an 164 // JSONReader::BuildValue() function from mis-treating a Unicode BOM as an
165 // invalid character and returning NULL. 165 // invalid character and returning NULL.
166 if (json.size() >= 3 && start_pos_[0] == 0xEF && 166 if (json.size() >= 3 && static_cast<uint8>(start_pos_[0]) == 0xEF &&
167 start_pos_[1] == 0xBB && start_pos_[2] == 0xBF) { 167 static_cast<uint8>(start_pos_[1]) == 0xBB &&
168 static_cast<uint8>(start_pos_[2]) == 0xBF) {
168 start_pos_ += 3; 169 start_pos_ += 3;
169 } 170 }
170 171
171 json_pos_ = start_pos_; 172 json_pos_ = start_pos_;
172 allow_trailing_comma_ = allow_trailing_comma; 173 allow_trailing_comma_ = allow_trailing_comma;
173 stack_depth_ = 0; 174 stack_depth_ = 0;
174 error_code_ = JSON_NO_ERROR; 175 error_code_ = JSON_NO_ERROR;
175 176
176 scoped_ptr<Value> root(BuildValue(check_root)); 177 scoped_ptr<Value> root(BuildValue(check_root));
177 if (root.get()) { 178 if (root.get()) {
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 ++column_number; 719 ++column_number;
719 } 720 }
720 } 721 }
721 722
722 error_line_ = line_number; 723 error_line_ = line_number;
723 error_col_ = column_number; 724 error_col_ = column_number;
724 error_code_ = error; 725 error_code_ = error;
725 } 726 }
726 727
727 } // namespace base 728 } // namespace base
OLDNEW
« no previous file with comments | « base/base.gyp ('k') | base/json/json_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698