Commit fa7b88fd authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[json] Fix error reporting when parsing an internalized one-byte string.

BUG=chromium:686010

Change-Id: I7bd4ab48f90a1013132bf037fd352ab55747189c
Reviewed-on: https://chromium-review.googlesource.com/451377
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43691}
parent f2408624
......@@ -720,6 +720,10 @@ Handle<String> JsonParser<seq_one_byte>::ScanJsonString() {
// Fast path for existing internalized strings. If the the string being
// parsed is not a known internalized string, contains backslashes or
// unexpectedly reaches the end of string, return with an empty handle.
// We intentionally use local variables instead of fields, compute hash
// while we are iterating a string and manually inline StringTable lookup
// here.
uint32_t running_hash = isolate()->heap()->HashSeed();
int position = position_;
uc32 c0 = c0_;
......@@ -731,11 +735,19 @@ Handle<String> JsonParser<seq_one_byte>::ScanJsonString() {
return SlowScanJsonString<SeqOneByteString, uint8_t>(source_, beg_pos,
position_);
}
if (c0 < 0x20) return Handle<String>::null();
if (c0 < 0x20) {
c0_ = c0;
position_ = position;
return Handle<String>::null();
}
running_hash = StringHasher::AddCharacterCore(running_hash,
static_cast<uint16_t>(c0));
position++;
if (position >= source_length_) return Handle<String>::null();
if (position >= source_length_) {
c0_ = kEndOfString;
position_ = position;
return Handle<String>::null();
}
c0 = seq_source_->SeqOneByteStringGet(position);
} while (c0 != '"');
int length = position - position_;
......
......@@ -789,6 +789,9 @@ void JSMessageObject::JSMessageObjectPrint(std::ostream& os) { // NOLINT
void String::StringPrint(std::ostream& os) { // NOLINT
if (!HasOnlyOneByteChars()) {
os << "u";
}
if (StringShape(this).IsInternalized()) {
os << "#";
} else if (StringShape(this).IsCons()) {
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function TryParse(s, message) {
try {
JSON.parse(s);
assertUnreachable();
} catch(e) {
assertEquals(message, e.message);
}
}
var s = `{"a\\\\b `;
TryParse(s, "Unexpected end of JSON input");
var s = `{"a\\\\\u03A9 `;
TryParse(s, "Unexpected end of JSON input");
var s = `{"ab `;
TryParse(s, "Unexpected end of JSON input");
var s = `{"a\u03A9 `;
TryParse(s, "Unexpected end of JSON input");
var s = `{"a\nb":"b"}`;
TryParse(s, "Unexpected token \n in JSON at position 3");
var s = `{"a\nb":"b\u03A9"}`;
TryParse(s, "Unexpected token \n in JSON at position 3");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment