Skip to content

Commit dea5e13

Browse files
authored
test(NODE-3447): serialization of BSON with embedded null bytes in strings (#460)
1 parent 71c6513 commit dea5e13

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

test/node/specs/bson-corpus/document.json

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
{
5252
"description": "Invalid subdocument: bad string length in field",
5353
"bson": "1C00000003666F6F001200000002626172000500000062617A000000"
54+
},
55+
{
56+
"description": "Null byte in sub-document key",
57+
"bson": "150000000378000D00000010610000010000000000"
5458
}
5559
]
5660
}

test/node/specs/bson-corpus/regex.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@
5454
],
5555
"decodeErrors": [
5656
{
57-
"description": "embedded null in pattern",
57+
"description": "Null byte in pattern string",
5858
"bson": "0F0000000B610061006300696D0000"
5959
},
6060
{
61-
"description": "embedded null in flags",
61+
"description": "Null byte in flags string",
6262
"bson": "100000000B61006162630069006D0000"
6363
}
6464
]

test/node/specs/bson-corpus/top.json

+22-3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@
7979
{
8080
"description": "Document truncated mid-key",
8181
"bson": "1200000002666F"
82+
},
83+
{
84+
"description": "Null byte in document key",
85+
"bson": "0D000000107800000100000000"
8286
}
8387
],
8488
"parseErrors": [
@@ -92,11 +96,11 @@
9296
},
9397
{
9498
"description": "Bad $regularExpression (pattern is number, not string)",
95-
"string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": 42, \"$options\" : \"\"}}}"
99+
"string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": 42, \"options\" : \"\"}}}"
96100
},
97101
{
98102
"description": "Bad $regularExpression (options are number, not string)",
99-
"string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": \"a\", \"$options\" : 0}}}"
103+
"string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": \"a\", \"options\" : 0}}}"
100104
},
101105
{
102106
"description" : "Bad $regularExpression (missing pattern field)",
@@ -241,7 +245,22 @@
241245
{
242246
"description": "Bad DBpointer (extra field)",
243247
"string": "{\"a\": {\"$dbPointer\": {\"a\": {\"$numberInt\": \"1\"}, \"$id\": {\"$oid\": \"56e1fc72e0c917e9c4714161\"}, \"c\": {\"$numberInt\": \"2\"}, \"$ref\": \"b\"}}}"
248+
},
249+
{
250+
"description" : "Null byte in document key",
251+
"string" : "{\"a\\u0000\": 1 }"
252+
},
253+
{
254+
"description" : "Null byte in sub-document key",
255+
"string" : "{\"a\" : {\"b\\u0000\": 1 }}"
256+
},
257+
{
258+
"description": "Null byte in $regularExpression pattern",
259+
"string": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"b\\u0000\", \"options\" : \"i\"}}}"
260+
},
261+
{
262+
"description": "Null byte in $regularExpression options",
263+
"string": "{\"a\" : {\"$regularExpression\" : { \"pattern\": \"b\", \"options\" : \"i\\u0000\"}}}"
244264
}
245-
246265
]
247266
}

0 commit comments

Comments
 (0)