From c1ccada2bc0f3eff3687da81876b65d4b7655a68 Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Mon, 31 Jul 2023 16:30:30 -0400 Subject: [PATCH 1/2] GODRIVER-2106 Sync code and symbol BSON corpus tests. --- testdata/bson-corpus/code.json | 26 +++++++++++++------------- testdata/bson-corpus/symbol.json | 14 +++++++------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/testdata/bson-corpus/code.json b/testdata/bson-corpus/code.json index 6f37349ad0..b8482b2541 100644 --- a/testdata/bson-corpus/code.json +++ b/testdata/bson-corpus/code.json @@ -20,48 +20,48 @@ }, { "description": "two-byte UTF-8 (\u00e9)", - "canonical_bson": "190000000261000D000000C3A9C3A9C3A9C3A9C3A9C3A90000", - "canonical_extjson": "{\"a\" : \"\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\"}" + "canonical_bson": "190000000D61000D000000C3A9C3A9C3A9C3A9C3A9C3A90000", + "canonical_extjson": "{\"a\" : {\"$code\" : \"\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\\u00e9\"}}" }, { "description": "three-byte UTF-8 (\u2606)", - "canonical_bson": "190000000261000D000000E29886E29886E29886E298860000", - "canonical_extjson": "{\"a\" : \"\\u2606\\u2606\\u2606\\u2606\"}" + "canonical_bson": "190000000D61000D000000E29886E29886E29886E298860000", + "canonical_extjson": "{\"a\" : {\"$code\" : \"\\u2606\\u2606\\u2606\\u2606\"}}" }, { "description": "Embedded nulls", - "canonical_bson": "190000000261000D0000006162006261620062616261620000", - "canonical_extjson": "{\"a\" : \"ab\\u0000bab\\u0000babab\"}" + "canonical_bson": "190000000D61000D0000006162006261620062616261620000", + "canonical_extjson": "{\"a\" : {\"$code\" : \"ab\\u0000bab\\u0000babab\"}}" } ], "decodeErrors": [ { "description": "bad code string length: 0 (but no 0x00 either)", - "bson": "0C0000000261000000000000" + "bson": "0C0000000D61000000000000" }, { "description": "bad code string length: -1", - "bson": "0C000000026100FFFFFFFF00" + "bson": "0C0000000D6100FFFFFFFF00" }, { "description": "bad code string length: eats terminator", - "bson": "10000000026100050000006200620000" + "bson": "100000000D6100050000006200620000" }, { "description": "bad code string length: longer than rest of document", - "bson": "120000000200FFFFFF00666F6F6261720000" + "bson": "120000000D00FFFFFF00666F6F6261720000" }, { "description": "code string is not null-terminated", - "bson": "1000000002610004000000616263FF00" + "bson": "100000000D610004000000616263FF00" }, { "description": "empty code string, but extra null", - "bson": "0E00000002610001000000000000" + "bson": "0E0000000D610001000000000000" }, { "description": "invalid UTF-8", - "bson": "0E00000002610002000000E90000" + "bson": "0E0000000D610002000000E90000" } ] } diff --git a/testdata/bson-corpus/symbol.json b/testdata/bson-corpus/symbol.json index 4e46cb9511..3dd3577ebd 100644 --- a/testdata/bson-corpus/symbol.json +++ b/testdata/bson-corpus/symbol.json @@ -50,31 +50,31 @@ "decodeErrors": [ { "description": "bad symbol length: 0 (but no 0x00 either)", - "bson": "0C0000000261000000000000" + "bson": "0C0000000E61000000000000" }, { "description": "bad symbol length: -1", - "bson": "0C000000026100FFFFFFFF00" + "bson": "0C0000000E6100FFFFFFFF00" }, { "description": "bad symbol length: eats terminator", - "bson": "10000000026100050000006200620000" + "bson": "100000000E6100050000006200620000" }, { "description": "bad symbol length: longer than rest of document", - "bson": "120000000200FFFFFF00666F6F6261720000" + "bson": "120000000E00FFFFFF00666F6F6261720000" }, { "description": "symbol is not null-terminated", - "bson": "1000000002610004000000616263FF00" + "bson": "100000000E610004000000616263FF00" }, { "description": "empty symbol, but extra null", - "bson": "0E00000002610001000000000000" + "bson": "0E0000000E610001000000000000" }, { "description": "invalid UTF-8", - "bson": "0E00000002610002000000E90000" + "bson": "0E0000000E610002000000E90000" } ] } From 8ff8309ff2be29c9177c4febb2766c0cd69e4ee0 Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Fri, 11 Aug 2023 18:53:00 -0400 Subject: [PATCH 2/2] update test assertion --- bson/bson_corpus_spec_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bson/bson_corpus_spec_test.go b/bson/bson_corpus_spec_test.go index 726d015ec8..8a27b06272 100644 --- a/bson/bson_corpus_spec_test.go +++ b/bson/bson_corpus_spec_test.go @@ -14,6 +14,7 @@ import ( "math" "os" "path" + "reflect" "strconv" "strings" "testing" @@ -407,8 +408,8 @@ func runTest(t *testing.T, file string) { // and assert that there was no error if any of the string or DBPointer values contain invalid UTF-8 // characters. for _, elem := range doc { - str, ok := elem.Value.(string) - invalidString := ok && !utf8.ValidString(str) + value := reflect.ValueOf(elem.Value) + invalidString := (value.Kind() == reflect.String) && !utf8.ValidString(value.String()) dbPtr, ok := elem.Value.(primitive.DBPointer) invalidDBPtr := ok && !utf8.ValidString(dbPtr.DB)