Skip to content

Commit

Permalink
GODRIVER-2106 Sync code and symbol BSON corpus tests. (#1338)
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyang-hu committed Nov 8, 2023
1 parent 4c68cc4 commit 7517da5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
5 changes: 3 additions & 2 deletions bson/bson_corpus_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"math"
"os"
"path"
"reflect"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -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)

Expand Down
26 changes: 13 additions & 13 deletions testdata/bson-corpus/code.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
14 changes: 7 additions & 7 deletions testdata/bson-corpus/symbol.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}

0 comments on commit 7517da5

Please sign in to comment.