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

Unified Diff: runtime/vm/json_test.cc

Issue 558853004: Preserve the contents of Dart strings with unmatched surrogate halfs by avoiding a UTF16 -> UTF8 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: sync and build 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 | « runtime/vm/json_stream.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/json_test.cc
diff --git a/runtime/vm/json_test.cc b/runtime/vm/json_test.cc
index 43e0dbc7c7c248c64f4ab1112c31aa4a7f1b9c83..2c2b4e28d1bd80bb6b4ceb70b5e625156395dc7f 100644
--- a/runtime/vm/json_test.cc
+++ b/runtime/vm/json_test.cc
@@ -6,6 +6,7 @@
#include "platform/json.h"
#include "vm/json_stream.h"
#include "vm/unit_test.h"
+#include "vm/dart_api_impl.h"
namespace dart {
@@ -315,6 +316,80 @@ TEST_CASE(JSON_JSONStream_EscapedString) {
}
+TEST_CASE(JSON_JSONStream_DartString) {
+ const char* kScriptChars =
+ "var ascii = 'Hello, World!';\n"
+ "var unicode = '\\u00CE\\u00F1\\u0163\\u00E9r\\u00F1\\u00E5\\u0163"
+ "\\u00EE\\u00F6\\u00F1\\u00E5\\u013C\\u00EE\\u017E\\u00E5\\u0163"
+ "\\u00EE\\u1EDD\\u00F1';\n"
+ "var surrogates = '\\u{1D11E}\\u{1D11E}\\u{1D11E}\\u{1D11E}"
+ "\\u{1D11E}';\n"
+ "var nullInMiddle = 'This has\\u0000 four words.';";
+
+ Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
+ EXPECT_VALID(lib);
+
+ Dart_Handle result;
+ String& obj = String::Handle();
+
+ {
+ result = Dart_GetField(lib, NewString("ascii"));
+ EXPECT_VALID(result);
+ obj ^= Api::UnwrapHandle(result);
+
+ JSONStream js;
+ {
+ JSONObject jsobj(&js);
+ jsobj.AddPropertyStr("ascci", obj);;
+ }
+ EXPECT_STREQ("{\"ascci\":\"Hello, World!\"}", js.ToCString());
+ }
+
+ {
+ result = Dart_GetField(lib, NewString("unicode"));
+ EXPECT_VALID(result);
+ obj ^= Api::UnwrapHandle(result);
+
+ JSONStream js;
+ {
+ JSONObject jsobj(&js);
+ jsobj.AddPropertyStr("unicode", obj);
+ }
+ EXPECT_STREQ("{\"unicode\":\"\\u00CE\\u00F1\\u0163\\u00E9r\\u00F1\\u00E5"
+ "\\u0163\\u00EE\\u00F6\\u00F1\\u00E5\\u013C\\u00EE\\u017E"
+ "\\u00E5\\u0163\\u00EE\\u1EDD\\u00F1\"}", js.ToCString());
+ }
+
+ {
+ result = Dart_GetField(lib, NewString("surrogates"));
+ EXPECT_VALID(result);
+ obj ^= Api::UnwrapHandle(result);
+
+ JSONStream js;
+ {
+ JSONObject jsobj(&js);
+ jsobj.AddPropertyStr("surrogates", obj);
+ }
+ EXPECT_STREQ("{\"surrogates\":\"\\uD834\\uDD1E\\uD834\\uDD1E\\uD834\\uDD1E"
+ "\\uD834\\uDD1E\\uD834\\uDD1E\"}", js.ToCString());
+ }
+
+ {
+ result = Dart_GetField(lib, NewString("nullInMiddle"));
+ EXPECT_VALID(result);
+ obj ^= Api::UnwrapHandle(result);
+
+ JSONStream js;
+ {
+ JSONObject jsobj(&js);
+ jsobj.AddPropertyStr("nullInMiddle", obj);
+ }
+ EXPECT_STREQ("{\"nullInMiddle\":\"This has\\u0000 four words.\"}",
+ js.ToCString());
+ }
+}
+
+
TEST_CASE(JSON_JSONStream_Options) {
const char* arguments[] = {"a", "b", "c"};
const char* option_keys[] = {"dog", "cat"};
« no previous file with comments | « runtime/vm/json_stream.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698