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

Unified Diff: runtime/vm/scanner_test.cc

Issue 10388179: Reject high- and low-surrogates in escaped code points. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: continue scanning after an invalid escaped code point Created 8 years, 7 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
« no previous file with comments | « runtime/vm/scanner.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/scanner_test.cc
diff --git a/runtime/vm/scanner_test.cc b/runtime/vm/scanner_test.cc
index 1ad68ab0403d0c6aea33d8ba1ea9edde4faba3a9..09e04c6e9858df80adb2d91018748a698be6dfa4 100644
--- a/runtime/vm/scanner_test.cc
+++ b/runtime/vm/scanner_test.cc
@@ -40,7 +40,7 @@ void CheckKind(const Scanner::GrowableTokenStream &token_stream,
Token::Kind kind) {
if (token_stream[index].kind != kind) {
OS::PrintErr("Token %d: expected kind %s but got %s\n", index,
- Token::Name(token_stream[index].kind), Token::Name(kind));
+ Token::Name(kind), Token::Name(token_stream[index].kind));
}
EXPECT_EQ(kind, token_stream[index].kind);
}
@@ -170,6 +170,79 @@ void StringEscapes() {
}
+void InvalidStringEscapes() {
+ const Scanner::GrowableTokenStream& high_start_4 =
+ Scan("\"\\uD800\"");
+ EXPECT_EQ(2, high_start_4.length());
+ CheckKind(high_start_4, 0, Token::kERROR);
+ EXPECT(high_start_4[0].literal->Equals("invalid code point"));
+ CheckKind(high_start_4, 1, Token::kEOS);
+
+ const Scanner::GrowableTokenStream& high_start_seq =
+ Scan("\"\\u{D800}\"");
+ EXPECT_EQ(2, high_start_seq.length());
+ CheckKind(high_start_seq, 0, Token::kERROR);
+ EXPECT(high_start_seq[0].literal->Equals("invalid code point"));
+ CheckKind(high_start_seq, 1, Token::kEOS);
+
+ const Scanner::GrowableTokenStream& high_end_4 =
+ Scan("\"\\uDBFF\"");
+ EXPECT_EQ(2, high_end_4.length());
+ CheckKind(high_end_4, 0, Token::kERROR);
+ EXPECT(high_end_4[0].literal->Equals("invalid code point"));
+ CheckKind(high_end_4, 1, Token::kEOS);
+
+ const Scanner::GrowableTokenStream& high_end_seq =
+ Scan("\"\\u{DBFF}\"");
+ EXPECT_EQ(2, high_end_seq.length());
+ CheckKind(high_end_seq, 0, Token::kERROR);
+ EXPECT(high_end_seq[0].literal->Equals("invalid code point"));
+ CheckKind(high_end_seq, 1, Token::kEOS);
+
+ const Scanner::GrowableTokenStream& low_start_4 =
+ Scan("\"\\uDC00\"");
+ EXPECT_EQ(2, low_start_4.length());
+ CheckKind(low_start_4, 0, Token::kERROR);
+ EXPECT(low_start_4[0].literal->Equals("invalid code point"));
+ CheckKind(low_start_4, 1, Token::kEOS);
+
+ const Scanner::GrowableTokenStream& low_start_seq =
+ Scan("\"\\u{DC00}\"");
+ EXPECT_EQ(2, low_start_seq.length());
+ CheckKind(low_start_seq, 0, Token::kERROR);
+ EXPECT(low_start_seq[0].literal->Equals("invalid code point"));
+ CheckKind(low_start_seq, 1, Token::kEOS);
+
+ const Scanner::GrowableTokenStream& low_end_4 =
+ Scan("\"\\uDFFF\"");
+ EXPECT_EQ(2, low_end_4.length());
+ CheckKind(low_end_4, 0, Token::kERROR);
+ EXPECT(low_end_4[0].literal->Equals("invalid code point"));
+ CheckKind(low_end_4, 1, Token::kEOS);
+
+ const Scanner::GrowableTokenStream& low_end_seq =
+ Scan("\"\\u{DFFF}\"");
+ EXPECT_EQ(2, low_end_seq.length());
+ CheckKind(low_end_seq, 0, Token::kERROR);
+ EXPECT(low_end_seq[0].literal->Equals("invalid code point"));
+ CheckKind(low_end_seq, 1, Token::kEOS);
+
+ const Scanner::GrowableTokenStream& out_of_range_low =
+ Scan("\"\\u{110000}\"");
+ EXPECT_EQ(2, out_of_range_low.length());
+ CheckKind(out_of_range_low, 0, Token::kERROR);
+ EXPECT(out_of_range_low[0].literal->Equals("invalid code point"));
+ CheckKind(out_of_range_low, 1, Token::kEOS);
+
+ const Scanner::GrowableTokenStream& out_of_range_high =
+ Scan("\"\\u{FFFFFF}\"");
+ EXPECT_EQ(2, out_of_range_high.length());
+ CheckKind(out_of_range_high, 0, Token::kERROR);
+ EXPECT(out_of_range_high[0].literal->Equals("invalid code point"));
+ CheckKind(out_of_range_high, 1, Token::kEOS);
+}
+
+
void RawString() {
// rs = @"\' \\"
const Scanner::GrowableTokenStream& tokens = Scan("rs = @\"\\\' \\\\\"");
@@ -358,6 +431,7 @@ TEST_CASE(Scanner_Test) {
CommentTest();
GreedIsGood();
StringEscapes();
+ InvalidStringEscapes();
RawString();
MultilineString();
EmptyString();
« no previous file with comments | « runtime/vm/scanner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698