summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBen Gertzfield <beng@fb.com>2016-04-28 12:27:38 -0700
committerBen Gertzfield <beng@fb.com>2016-05-23 16:38:55 -0700
commit6704b19db65727d9afbc74e92733516693df9b18 (patch)
tree941ee2f927d7a870f2444d3ad46d43df3cc80bae /tests
parent208c15f29da17d21bae97705c3242d69b514cf70 (diff)
downloadflatbuffers-6704b19db65727d9afbc74e92733516693df9b18.tar.gz
flatbuffers-6704b19db65727d9afbc74e92733516693df9b18.tar.bz2
flatbuffers-6704b19db65727d9afbc74e92733516693df9b18.zip
Handle \u-escaped surrogate pairs correctly in IDL parser
Diffstat (limited to 'tests')
-rw-r--r--tests/test.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/test.cpp b/tests/test.cpp
index e636f1f3..df9cf08b 100644
--- a/tests/test.cpp
+++ b/tests/test.cpp
@@ -859,6 +859,44 @@ void UnicodeTest() {
"\\u5225\\u30B5\\u30A4\\u30C8\\x01\\x80\"}", true);
}
+void UnicodeSurrogatesTest() {
+ flatbuffers::Parser parser;
+
+ TEST_EQ(
+ parser.Parse(
+ "table T { F:string (id: 0); }"
+ "root_type T;"
+ "{ F:\"\\uD83D\\uDCA9\"}"), true);
+ auto root = flatbuffers::GetRoot<flatbuffers::Table>(
+ parser.builder_.GetBufferPointer());
+ auto string = root->GetPointer<flatbuffers::String *>(
+ flatbuffers::FieldIndexToOffset(0));
+ TEST_EQ(strcmp(string->c_str(), "\xF0\x9F\x92\xA9"), 0);
+}
+
+void UnicodeInvalidSurrogatesTest() {
+ TestError(
+ "table T { F:string; }"
+ "root_type T;"
+ "{ F:\"\\uD800\"}", "unpaired high surrogate");
+ TestError(
+ "table T { F:string; }"
+ "root_type T;"
+ "{ F:\"\\uD800abcd\"}", "unpaired high surrogate");
+ TestError(
+ "table T { F:string; }"
+ "root_type T;"
+ "{ F:\"\\uD800\\n\"}", "unpaired high surrogate");
+ TestError(
+ "table T { F:string; }"
+ "root_type T;"
+ "{ F:\"\\uD800\\uD800\"}", "multiple high surrogates");
+ TestError(
+ "table T { F:string; }"
+ "root_type T;"
+ "{ F:\"\\uDC00\"}", "unpaired low surrogate");
+}
+
void UnknownFieldsTest() {
flatbuffers::IDLOptions opts;
opts.skip_unexpected_fields_in_json = true;
@@ -907,6 +945,8 @@ int main(int /*argc*/, const char * /*argv*/[]) {
EnumStringsTest();
IntegerOutOfRangeTest();
UnicodeTest();
+ UnicodeSurrogatesTest();
+ UnicodeInvalidSurrogatesTest();
UnknownFieldsTest();
if (!testing_fails) {