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

Unified Diff: runtime/vm/dart_api_impl_test.cc

Issue 563043003: Don't crash when generating error messages with malformed strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 | « no previous file | runtime/vm/unicode.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl_test.cc
diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc
index 4b0b5d51fccaf47a031352c86564b57888497486..d63e46c14504704b975856dd634d850eaac60c7c 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -1040,6 +1040,30 @@ TEST_CASE(NewString) {
}
+TEST_CASE(MalformedStringToUTF8) {
+ const char* kScriptChars =
+ "String testMain() {"
+ " return '\\u{1D11E}'[1];"
+ "}";
+
+ Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
+ Dart_Handle str1 = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
+ EXPECT_VALID(str1);
+
+ uint8_t* utf8_encoded = NULL;
+ intptr_t utf8_length = 0;
+ Dart_Handle result = Dart_StringToUTF8(str1, &utf8_encoded, &utf8_length);
+ EXPECT_VALID(result);
+ EXPECT_EQ(3, utf8_length);
+ EXPECT_EQ(237, static_cast<intptr_t>(utf8_encoded[0]));
+ EXPECT_EQ(180, static_cast<intptr_t>(utf8_encoded[1]));
+ EXPECT_EQ(158, static_cast<intptr_t>(utf8_encoded[2]));
+
+ Dart_Handle str2 = Dart_NewStringFromUTF8(utf8_encoded, utf8_length);
+ EXPECT(Dart_IsError(str2)); // Invalid UTF-8.
+}
+
+
static void ExternalStringCallbackFinalizer(void* peer) {
*static_cast<int*>(peer) *= 2;
}
« no previous file with comments | « no previous file | runtime/vm/unicode.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698