Reland [skjson] Size-constrained input API
Pass an explicit input size instead of requiring a C string.
Thanks to mtklein's clever trick, this has no measurable perf impact.
TBR=
Change-Id: Ic8cb1dc75f4d0814e5b2c80038d1b8d3a7b072ab
Reviewed-on: https://skia-review.googlesource.com/134946
Reviewed-by: Florin Malita <fmalita@chromium.org>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/modules/skjson/src/SkJSONTest.cpp b/modules/skjson/src/SkJSONTest.cpp
index 6d4338c..91ae497 100644
--- a/modules/skjson/src/SkJSONTest.cpp
+++ b/modules/skjson/src/SkJSONTest.cpp
@@ -22,8 +22,14 @@
{ "" , nullptr },
{ "[" , nullptr },
{ "]" , nullptr },
+ { "[[]" , nullptr },
+ { "[]]" , nullptr },
+ { "[]f" , nullptr },
{ "{" , nullptr },
{ "}" , nullptr },
+ { "{{}" , nullptr },
+ { "{}}" , nullptr },
+ { "{}f" , nullptr },
{ "{]" , nullptr },
{ "[}" , nullptr },
{ "1" , nullptr },
@@ -51,7 +57,9 @@
{ "{ \"k\" : null \"k\" : 1 }", nullptr },
+ { "[]" , "[]" },
{ " \n\r\t [ \n\r\t ] \n\r\t " , "[]" },
+ { "[[]]" , "[[]]" },
{ "[ null ]" , "[null]" },
{ "[ true ]" , "[true]" },
{ "[ false ]" , "[false]" },
@@ -66,6 +74,7 @@
{ "[ \"123456789\" ]" , "[\"123456789\"]" },
{ "[ null , true, false,0,12.8 ]", "[null,true,false,0,12.8]" },
+ { "{}" , "{}" },
{ " \n\r\t { \n\r\t } \n\r\t " , "{}" },
{ "{ \"k\" : null }" , "{\"k\":null}" },
{ "{ \"k1\" : null, \"k2 \":0 }", "{\"k1\":null,\"k2 \":0}" },
@@ -89,7 +98,7 @@
};
for (const auto& tst : g_tests) {
- DOM dom(tst.in);
+ DOM dom(tst.in, strlen(tst.in));
const auto success = !dom.root().is<NullValue>();
REPORTER_ASSERT(reporter, success == (tst.out != nullptr));
if (!success) continue;
@@ -153,7 +162,7 @@
\"k8\": { \"kk1\": 2, \"kk2\": false, \"kk1\": \"baz\" } \n\
}";
- DOM dom(json);
+ DOM dom(json, strlen(json));
const auto& jroot = dom.root().as<ObjectValue>();
REPORTER_ASSERT(reporter, jroot.is<ObjectValue>());