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

Unified Diff: test/cctest/parsing/test-scanner-streams.cc

Issue 2391273002: Fix bad-char handling in utf-8 streaming streams. Also add test. (Closed)
Patch Set: Improve comments. Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« src/parsing/scanner-character-streams.cc ('K') | « src/unicode.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/parsing/test-scanner-streams.cc
diff --git a/test/cctest/parsing/test-scanner-streams.cc b/test/cctest/parsing/test-scanner-streams.cc
index bf2762485708d5dacb5a7952df7824f9e94c901a..fffd1200f20621d1aba7469e1d06bfa3b61bb26a 100644
--- a/test/cctest/parsing/test-scanner-streams.cc
+++ b/test/cctest/parsing/test-scanner-streams.cc
@@ -423,3 +423,26 @@ TEST(CharacterStreams) {
TestCharacterStreams(buffer, arraysize(buffer) - 1);
TestCharacterStreams(buffer, arraysize(buffer) - 1, 576, 3298);
}
+
+// Regression test for crbug.com/651333. Read invalid utf-8.
+TEST(Regress651333) {
+ const uint8_t bytes[] =
+ "A\xf1"
+ "ad"; // Anad, with n == n-with-tilde.
+ const uint16_t unicode[] = {65, 65533, 97, 100};
+
+ // Run the test for all sub-strings 0..N of bytes, to make sure we hit the
+ // error condition in and at chunk boundaries.
+ for (size_t len = 0; len < arraysize(bytes); len++) {
+ // Read len bytes from bytes, and compare against the expected unicode
+ // characters. Expect kBadChar ( == Unicode replacement char == code point
+ // 65533) instead of the incorrectly coded Latin1 char.
+ ChunkSource chunks(bytes, len, false);
+ std::unique_ptr<i::Utf16CharacterStream> stream(i::ScannerStream::For(
+ &chunks, v8::ScriptCompiler::StreamedSource::UTF8));
+ for (size_t i = 0; i < len; i++) {
+ CHECK_EQ(unicode[i], stream->Advance());
+ }
+ CHECK_EQ(i::Utf16CharacterStream::kEndOfInput, stream->Advance());
+ }
+}
« src/parsing/scanner-character-streams.cc ('K') | « src/unicode.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698