Skip to content

Commit a9e24eb

Browse files
committed
Merge upstream/develop; reconcile operator>> caveat with #5343
#5343 landed the authoritative operator>> number-terminator caveat in operator_gtgt.md, so take that version and replace the now-redundant caveat on the parsing feature page with a pointer to it. README corrections (test-data is downloaded not vendored; strict parse() coverage attributed to the updated suite) are unaffected. Signed-off-by: manon <youdie006@users.noreply.github.com>
2 parents 75a3b00 + 5f121d8 commit a9e24eb

24 files changed

Lines changed: 755 additions & 126 deletions

File tree

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ jobs:
3838

3939
# Initializes the CodeQL tools for scanning.
4040
- name: Initialize CodeQL
41-
uses: github/codeql-action/init@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1
41+
uses: github/codeql-action/init@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
4242
with:
4343
languages: c-cpp
4444

4545
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
4646
# If this step fails, then you should remove it and run the build manually (see below)
4747
- name: Autobuild
48-
uses: github/codeql-action/autobuild@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1
48+
uses: github/codeql-action/autobuild@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
4949

5050
- name: Perform CodeQL Analysis
51-
uses: github/codeql-action/analyze@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1
51+
uses: github/codeql-action/analyze@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3

.github/workflows/flawfinder.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ jobs:
4343
output: 'flawfinder_results.sarif'
4444

4545
- name: Upload analysis results to GitHub Security tab
46-
uses: github/codeql-action/upload-sarif@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1
46+
uses: github/codeql-action/upload-sarif@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
4747
with:
4848
sarif_file: ${{github.workspace}}/flawfinder_results.sarif

.github/workflows/scorecards.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
persist-credentials: false
4747

4848
- name: "Run analysis"
49-
uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
49+
uses: ossf/scorecard-action@2d1146689b8cda280b9bc96326124645441f03bc # v2.4.4
5050
with:
5151
results_file: results.sarif
5252
results_format: sarif
@@ -76,6 +76,6 @@ jobs:
7676

7777
# Upload the results to GitHub's code scanning dashboard.
7878
- name: "Upload to code-scanning"
79-
uses: github/codeql-action/upload-sarif@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1
79+
uses: github/codeql-action/upload-sarif@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
8080
with:
8181
sarif_file: results.sarif

.github/workflows/semgrep.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161

6262
# Upload SARIF file generated in previous step
6363
- name: Upload SARIF file
64-
uses: github/codeql-action/upload-sarif@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1
64+
uses: github/codeql-action/upload-sarif@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
6565
with:
6666
sarif_file: semgrep.sarif
6767
if: always()

docs/mkdocs/docs/api/basic_json/binary_t.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ is compatible with both of the binary data formats that use binary subtyping, (t
1313
incompatible with each other, and it is up to the user to translate between them). The subtype is added to `BinaryType`
1414
via the helper type [byte_container_with_subtype](../byte_container_with_subtype/index.md).
1515

16-
[CBOR's RFC 7049](https://tools.ietf.org/html/rfc7049) describes this type as:
17-
> Major type 2: a byte string. The string's length in bytes is represented following the rules for positive integers
18-
> (major type 0).
16+
[CBOR's RFC 8949](https://www.rfc-editor.org/rfc/rfc8949.html#section-3.1) describes this type as:
17+
> Major type 2: A byte string. The number of bytes in the string is equal to the argument.
1918
2019
[MessagePack's documentation on the bin type
2120
family](https://github.com/msgpack/msgpack/blob/master/spec.md#bin-format-family) describes this type as:

docs/mkdocs/docs/api/basic_json/to_bson.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Strong guarantee: if an exception is thrown, there are no changes in the JSON va
4040
is not an object; example: `"to serialize to BSON, top-level type must be object, but is string"`
4141
- Throws [`out_of_range.409`](../../home/exceptions.md#jsonexceptionout_of_range409) if a key in the JSON object contains
4242
a null byte (code point U+0000); example: `"BSON key cannot contain code point U+0000 (at byte 2)"`
43+
- Throws [`out_of_range.412`](../../home/exceptions.md#jsonexceptionout_of_range412) if the length of a document, array,
44+
string, or binary value exceeds the range of the 32-bit BSON length field; example:
45+
`"BSON length 2147483661 exceeds maximum of 2147483647"`
4346
4447
## Complexity
4548

docs/mkdocs/docs/api/operator_gtgt.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,44 @@ A UTF-8 byte order mark is silently ignored.
3333
Invalid Unicode escapes and unpaired surrogates in the input are reported as
3434
[`parse_error.101`](../home/exceptions.md#jsonexceptionparse_error101) with a detailed message.
3535

36-
`operator>>` parses exactly one JSON value and leaves the stream positioned right after it, so it can be called
37-
repeatedly to read a sequence of concatenated JSON values from the same stream:
36+
`operator>>` parses exactly one JSON value, so it can be called repeatedly to read a sequence of concatenated JSON
37+
values from the same stream:
3838

3939
```cpp
4040
json j1, j2;
41-
input >> j1; // parses the first value, stream now positioned right after it
41+
input >> j1; // parses the first value
4242
input >> j2; // parses the next value
4343
```
4444

45-
A number is terminated only by the character that follows it, and `operator>>` consumes that character, so consecutive
46-
numbers must be whitespace-separated: `1 2` reads as two values, but in `1true` the terminating `t` is consumed together
47-
with the `1`, leaving `rue` in the stream so the next extraction fails. Structural and literal values are self-delimiting
48-
and are not affected.
45+
!!! warning "A number must be followed by whitespace"
4946

50-
Note this does **not** work for [JSON Lines](../features/parsing/json_lines.md) (newline-delimited JSON) input --
51-
see that page for why and for the recommended alternative.
47+
A number is only terminated by the character that follows it. That character is read from the stream to detect the
48+
end of the number, and it is **not** put back. When a value that is a number is immediately followed by the next
49+
value, the first character of that next value is lost:
50+
51+
```cpp
52+
std::istringstream input("1true");
53+
json j1, j2;
54+
input >> j1; // j1 == 1
55+
input >> j2; // throws parse_error.101: the stream now starts at "rue"
56+
```
57+
58+
Separating the values with whitespace avoids this, because the character that is eaten is then the separator:
59+
60+
```cpp
61+
std::istringstream input("1 true");
62+
json j1, j2;
63+
input >> j1; // j1 == 1
64+
input >> j2; // j2 == true
65+
```
66+
67+
Only numbers are affected. Values ending in a self-delimiting character do not read past themselves, so
68+
`truefalse`, `[1][2]`, `{"a":1}{"b":2}`, and `"a""b"` can be read back to back without a separator.
69+
70+
This is tracked in [#5340](https://github.com/nlohmann/json/issues/5340).
71+
72+
Note that reading concatenated values does **not** work for [JSON Lines](../features/parsing/json_lines.md)
73+
(newline-delimited JSON) input -- see that page for why and for the recommended alternative.
5274

5375
!!! warning "Deprecation"
5476

docs/mkdocs/docs/features/binary_formats/bson.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ The library uses the following mapping from JSON values types to BSON types:
3535
The mapping is **incomplete**, since only JSON-objects (and things contained therein) can be serialized to BSON.
3636
Also, keys may not contain U+0000, since they are serialized a zero-terminated c-strings.
3737

38+
!!! warning "BSON type 0x11 interoperability"
39+
40+
The BSON specification defines type `0x11` as a Timestamp. This library uses marker `0x11` when serializing
41+
`number_unsigned` values in the range `9223372036854775808..18446744073709551615`. Other BSON implementations may
42+
therefore interpret these values as Timestamps instead of unsigned integers.
43+
44+
!!! info "Binary values without a subtype"
45+
46+
BSON requires every binary value to have a subtype. If a binary value has no subtype, this library serializes it
47+
with the generic subtype `0x00`. After deserialization, `has_subtype()` returns `true` and `subtype()` returns `0`.
48+
As a result, serializing and deserializing a JSON object containing such a value produces a different JSON object,
49+
even though the binary data is unchanged.
50+
3851
??? example
3952

4053
```cpp
@@ -82,8 +95,8 @@ The library maps BSON record types to JSON value types as follows:
8295

8396
!!! note "Handling of BSON type 0x11"
8497

85-
BSON type 0x11 is used to represent uint64 numbers. This library treats these values purely as uint64 numbers
86-
and does not parse them into date-related formats.
98+
This library deserializes BSON type `0x11` (Timestamp) as a `number_unsigned` value. The 64-bit value is preserved,
99+
but the Timestamp type information is not.
87100

88101
??? example
89102

docs/mkdocs/docs/features/binary_formats/cbor.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ extremely small code sizes, fairly small message size, and extensibility without
77

88
- [CBOR Website](http://cbor.io) - the main source on CBOR
99
- [CBOR Playground](http://cbor.me) - an interactive webpage to translate between JSON and CBOR
10-
- [RFC 7049](https://tools.ietf.org/html/rfc7049) - the CBOR specification
10+
- [RFC 8949](https://www.rfc-editor.org/rfc/rfc8949.html) - the CBOR specification
1111

1212
## Serialization
1313

1414
The library uses the following mapping from JSON values types to CBOR types according to the CBOR specification
15-
([RFC 7049](https://www.rfc-editor.org/rfc/rfc7049.html)):
15+
([RFC 8949](https://www.rfc-editor.org/rfc/rfc8949.html)):
1616

1717
| JSON value type | value/range | CBOR type | first byte |
1818
|-----------------|--------------------------------------------|-----------------------------------|------------|

docs/mkdocs/docs/features/parsing/index.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ what makes it possible to read several concatenated values from the same stream,
4040
document followed by trailing bytes" is accepted rather than rejected. If you are validating conformance, or need to
4141
reject any input that is not exactly one JSON document, prefer `parse`.
4242
43-
One caveat when relying on this for concatenated values: a number is terminated only by the character that follows it,
44-
and `operator>>` consumes that character, so consecutive numbers must be whitespace-separated. `1 2` reads as two
45-
values, but in `1true` the terminating `t` is consumed together with the `1`, leaving `rue` in the stream, so the next
46-
extraction fails. Structural and literal values (objects, arrays, strings, `true`/`false`/`null`) are self-delimiting
47-
and are not affected.
43+
When using `operator>>` to read several concatenated values this way, a value that is a number must be followed by
44+
whitespace, because `operator>>` consumes the character that terminates a number — see the
45+
[`operator>>` notes](../../api/operator_gtgt.md#notes) for details and examples.
4846
4947
## SAX vs. DOM parsing
5048

0 commit comments

Comments
 (0)