@@ -9,8 +9,8 @@ BSON Corpus
9
9
:Status: Approved
10
10
:Type: Standards
11
11
:Minimum Server Version: N/A
12
- :Last Modified: July 20, 2017
13
- :Version: 2.0
12
+ :Last Modified: September 2, 2021
13
+ :Version: 2.1
14
14
15
15
.. contents ::
16
16
@@ -140,7 +140,7 @@ additional assertions. For each case, keys include:
140
140
JSON document. Because this is itself embedded as a *string * inside a JSON
141
141
document, characters like quote and backslash are escaped. It may be
142
142
present for deprecated types and is the Canonical Extended JSON
143
- representation of ``converted_bson`.
143
+ representation of ``converted_bson `` .
144
144
145
145
* ``lossy `` (optional) -- boolean; present (and true) iff ``canonical_bson ``
146
146
can't be represented exactly with extended JSON (e.g. NaN with a payload).
@@ -167,15 +167,6 @@ be encoded to the ``bson_type`` under test. For each case, keys include:
167
167
* ``string ``: a text or numeric representation of an input that can't be
168
168
parsed to a valid value of the given type.
169
169
170
- Drivers MUST parse the extended JSON input using a regular JSON parser
171
- (not an extended JSON one) and verify the input is parsed successfully.
172
- This serves to verify that the parse error test cases test extended
173
- JSON-specific error conditions and that they do not have,
174
- for example, unintended spelling errors.
175
-
176
- Drivers SHOULD parse the extended JSON input using the extended JSON parser
177
- and verify the parsing produces an extended JSON parse error.
178
-
179
170
Extended JSON encoding, escaping and ordering
180
171
---------------------------------------------
181
172
@@ -314,21 +305,48 @@ manner.
314
305
Testing parsing errors
315
306
----------------------
316
307
317
- The interpretation of ``parseErrors `` is type-specific. For example,
318
- helpers for creating Decimal128 values may parse strings to convert them
319
- to binary Decimal128 values. The ``parseErrors `` cases are strings that
320
- will *not * convert correctly.
308
+ The interpretation of ``parseErrors `` is type-specific. The structure of test
309
+ cases within ``parseErrors `` is described in `Parse error case keys `_.
321
310
322
- The documentation for a type (if any) will specify how to use these
323
- cases for testing.
311
+ Drivers SHOULD test that each case results in a parsing error (e.g. parsing
312
+ Extended JSON, constructing a language type). Implementations MAY test
313
+ assertions in an implementation-specific manner.
324
314
325
- For type "0x00" (i.e. top-level documents), the ``parseErrors `` entries have a
326
- ``description `` field and an ``string `` field. Parsing the ``string `` field
327
- as Extended JSON MUST result in an error.
328
315
329
- Drivers SHOULD test that each case results in a parse error.
330
- Implementations MAY test assertions in an implementation-specific
331
- manner.
316
+ Top-level Document (type 0x00)
317
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
318
+
319
+ For type "0x00" (i.e. top-level documents), the ``string `` field contains input
320
+ for an Extended JSON parser. Drivers MUST parse the Extended JSON input using an
321
+ Extended JSON parser and verify that doing so yields an Extended JSON parsing
322
+ error.
323
+
324
+ Drivers SHOULD also parse the Extended JSON input using a regular JSON parser (not
325
+ an Extended JSON one) and verify the input is parsed successfully. This serves
326
+ to verify that the ``parseErrors `` test cases are testing Extended JSON-specific
327
+ error conditions and that they do not have, for example, unintended syntax
328
+ errors.
329
+
330
+ Note: due to the generic nature of these tests, they may also be used to test
331
+ Extended JSON parsing errors for various BSON types appearing within a document.
332
+
333
+
334
+ Binary (type 0x05)
335
+ ~~~~~~~~~~~~~~~~~~
336
+
337
+ For type "0x05" (i.e. binary), the rules for handling ``parseErrors `` are the
338
+ same as those for `Top-level Document (type 0x00) `_.
339
+
340
+
341
+ Decimal128 (type 0x13)
342
+ ~~~~~~~~~~~~~~~~~~~~~~
343
+
344
+ For type "0x13" (i.e. Decimal128), the ``string `` field contains input for a
345
+ Decimal128 parser that converts string input to a binary Decimal128 value (e.g.
346
+ Decimal128 constructor). Drivers MUST assert that these strings cannot be
347
+ successfully converted to a binary Decimal128 value and that parsing the string
348
+ produces an error.
349
+
332
350
333
351
Deprecated types
334
352
----------------
@@ -338,6 +356,29 @@ Implementations MAY ignore or modify them to match legacy treatment of
338
356
deprecated types. The ``converted_bson `` and ``converted_extjson `` fields MAY
339
357
be used to test conversion to a standard type or MAY be ignored.
340
358
359
+ Prose Tests
360
+ ===========
361
+
362
+ The following tests have not yet been automated, but MUST still be tested.
363
+
364
+ 1. Prohibit null bytes in null-terminated strings when encoding BSON
365
+ --------------------------------------------------------------------
366
+
367
+ The BSON spec uses null-terminated strings to represent document field names and
368
+ regex components (i.e. pattern and flags/options). Drivers MUST assert that null
369
+ bytes are prohibited in the following contexts when encoding BSON (i.e. creating
370
+ raw BSON bytes or constructing BSON-specific type classes):
371
+
372
+ * Field name within a root document
373
+ * Field name within a sub-document
374
+ * Pattern for a regular expression
375
+ * Flags/options for a regular expression
376
+
377
+ Depending on how drivers implement BSON encoding, they MAY expect an error when
378
+ constructing a type class (e.g. BSON Document or Regex class) or when encoding a
379
+ language representation to BSON (e.g. converting a dictionary, which might allow
380
+ null bytes in its keys, to raw BSON bytes).
381
+
341
382
Implementation Notes
342
383
====================
343
384
@@ -456,6 +497,13 @@ assertions. This makes for easier and safer test case development.
456
497
Changes
457
498
=======
458
499
500
+ Version 2.1 - September 2, 2021
501
+
502
+ * Add spec and prose tests for prohibiting null bytes in null-terminated strings
503
+ within document field names and regular expressions.
504
+
505
+ * Clarify type-specific rules for ``parseErrors ``.
506
+
459
507
Version 2.0 - May 26, 2017
460
508
461
509
* Revised to be consistent with Extended JSON spec 2.0: valid case fields
0 commit comments