Skip to content

Commit

Permalink
fix(json_parser): handle unterminated strings as bogus values (#2621)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos authored Apr 28, 2024
1 parent cf48a89 commit 1abda0c
Show file tree
Hide file tree
Showing 67 changed files with 840 additions and 816 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

#### Bug fixes

- [noDuplicateJsonKeys](https://biomejs.dev/linter/rules/no-duplicate-json-keys/) no longer crashes when a JSON file contains an unterminated string ([#2357](https://github.com/biomejs/biome/issues/2357)).
Contributed by @Conaclos

- [noRedeclare](https://biomejs.dev/linter/rules/no-redeclare/) now reports redeclarations of parameters in a functions body ([#2394](https://github.com/biomejs/biome/issues/2394)).

The rule was unable to detect redeclarations of a parameter or type parameter in the function body.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
source: crates/biome_formatter_test/src/snapshot_builder.rs
info: json/json/json5.json
---

# Input

```json
Expand Down Expand Up @@ -133,6 +132,19 @@ json5.json:3:3 parse ━━━━━━━━━━━━━━━━━━━
i Use double quotes to escape the string.
json5.json:3:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× expected `,` but instead found `:`
1 │ [
2 │ {
> 3 │ '//': 'JSON5 allow `Infinity` and `NaN`',
│ ^
4 │ numbers: [
5Infinity,
i Remove :
json5.json:3:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× JSON standard does not allow single quoted strings
Expand All @@ -146,32 +158,54 @@ json5.json:3:9 parse ━━━━━━━━━━━━━━━━━━━
i Use double quotes to escape the string.
json5.json:5:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
json5.json:4:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× String values must be double quoted.
2 │ {
3 │ '//': 'JSON5 allow `Infinity` and `NaN`',
4numbers: [
> 5 Infinity,
^^^^^^^^
> 4 │ numbers: [
^^^^^^^
5 Infinity,
6-Infinity,
7NaN,
json5.json:4:10 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× expected `,` but instead found `:`
2 │ {
3 │ '//': 'JSON5 allow `Infinity` and `NaN`',
> 4 │ numbers: [
^
5Infinity,
6-Infinity,
i Remove :
json5.json:4:12 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× End of file expected
× expected `,` but instead found `[`
2 │ {
3 │ '//': 'JSON5 allow `Infinity` and `NaN`',
> 4 │ numbers: [
^
5Infinity,
6-Infinity,
i Remove [
json5.json:5:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× String values must be double quoted.
3'//': 'JSON5 allow `Infinity` and `NaN`',
4numbers: [
> 5Infinity,
^^^^^^^^^
^^^^^^^^
6-Infinity,
7NaN,
i Use an array for a sequence of values: `[1, 2]`
json5.json:6:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Minus must be followed by a digit
Expand All @@ -183,6 +217,122 @@ json5.json:6:5 parse ━━━━━━━━━━━━━━━━━━━
7NaN,
8 │ ],
json5.json:6:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× expected `,` but instead found `Infinity`
4numbers: [
5Infinity,
> 6-Infinity,
^^^^^^^^
7NaN,
8 │ ],
i Remove Infinity
json5.json:7:5 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× String values must be double quoted.
5Infinity,
6-Infinity,
> 7NaN,
^^^
8 │ ],
9Infinity: NaN,
json5.json:8:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Expected an array, an object, or a literal but instead found ']'.
6-Infinity,
7NaN,
> 8 │ ],
^
9Infinity: NaN,
10NaN: Infinity,
i Expected an array, an object, or a literal here.
6-Infinity,
7NaN,
> 8 │ ],
│ ^
9 │ Infinity: NaN,
10 │ NaN: Infinity,
json5.json:9:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× String values must be double quoted.
7NaN,
8 │ ],
> 9 │ Infinity: NaN,
│ ^^^^^^^^
10 │ NaN: Infinity,
11 │ NaN: -Infinity,
json5.json:9:11 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× expected `,` but instead found `:`
7NaN,
8 │ ],
> 9 │ Infinity: NaN,
│ ^
10 │ NaN: Infinity,
11 │ NaN: -Infinity,
i Remove :
json5.json:10:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× String values must be double quoted.
8 │ ],
9 │ Infinity: NaN,
> 10 │ NaN: Infinity,
│ ^^^
11 │ NaN: -Infinity,
12 │ },
json5.json:10:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× expected `,` but instead found `:`
8 │ ],
9 │ Infinity: NaN,
> 10 │ NaN: Infinity,
│ ^
11 │ NaN: -Infinity,
12 │ },
i Remove :
json5.json:11:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× String values must be double quoted.
9Infinity: NaN,
10NaN: Infinity,
> 11NaN: -Infinity,
^^^
12 │ },
13 │ {
json5.json:11:6 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× expected `,` but instead found `:`
9Infinity: NaN,
10 │ NaN: Infinity,
> 11 │ NaN: -Infinity,
│ ^
12 │ },
13 │ {
i Remove :
json5.json:11:8 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Minus must be followed by a digit
Expand All @@ -194,6 +344,26 @@ json5.json:11:8 parse ━━━━━━━━━━━━━━━━━━━
12 │ },
13 │ {
json5.json:12:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Expected an array, an object, or a literal but instead found '}'.
10NaN: Infinity,
11NaN: -Infinity,
> 12 │ },
^
13 │ {
14 │ '//': 'JSON5 numbers',
i Expected an array, an object, or a literal here.
10 │ NaN: Infinity,
11 │ NaN: -Infinity,
> 12 │ },
^
13 │ {
14 │ '//': 'JSON5 numbers',
json5.json:13:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× End of file expected
Expand All @@ -220,6 +390,21 @@ json5.json:14:3 parse ━━━━━━━━━━━━━━━━━━━
i Use double quotes to escape the string.
json5.json:14:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× End of file expected
12 │ },
13 │ {
> 14 │ '//': 'JSON5 numbers',
│ ^^^^^^^^^^^^^^^^^^
> 15 │ hexadecimal: 0xdecaf,
│ ^^^^^^^^^^^^
16 │ leadingDecimalPoint: .8675309, andTrailing: 8675309.,
17 │ positiveSign: +1,
i Use an array for a sequence of values: `[1, 2]`
json5.json:14:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× JSON standard does not allow single quoted strings
Expand Down Expand Up @@ -389,6 +574,24 @@ json5.json:20:3 parse ━━━━━━━━━━━━━━━━━━━
i Use double quotes to escape the string.
json5.json:20:7 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× End of file expected
18 │ },
19 │ {
> 20 │ '//': 'JSON5 strings',
│ ^^^^^^^^^^^^^^^^^^
> 21 │ singleQuotes: 'I can use "double quotes" here',
> 22 │ lineBreaks: "Look, Mom! \
> 23 │ No \\n's!",
> 24 │ }
> 25 │ ]
^
26
i Use an array for a sequence of values: `[1, 2]`
json5.json:20:9 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× JSON standard does not allow single quoted strings
Expand All @@ -415,19 +618,6 @@ json5.json:21:15 parse ━━━━━━━━━━━━━━━━━━━
i Use double quotes to escape the string.
json5.json:22:15 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× End of file expected
20'//': 'JSON5 strings',
21 │ singleQuotes: 'I can use "double quotes" here',
> 22 │ lineBreaks: "Look, Mom! \
│ ^^^^^^^^^^^^^
23No \\n's!",
24 │ }
i Use an array for a sequence of values: `[1, 2]`
json5.json:22:27 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Invalid escape sequence
Expand Down Expand Up @@ -465,17 +655,6 @@ json5.json:22:15 parse ━━━━━━━━━━━━━━━━━━━
24 │ }
25 │ ]
json5.json:23:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× String values must be double quoted.
21singleQuotes: 'I can use "double quotes" here',
22lineBreaks: "Look, Mom! \
> 23 │ No \\n's!",
^^
24 │ }
25 │ ]
json5.json:23:4 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× unexpected character `\`
Expand Down Expand Up @@ -520,21 +699,5 @@ json5.json:23:7 parse ━━━━━━━━━━━━━━━━━━━
25 │ ]
26 │
json5.json:24:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× End of file expected
22 │ lineBreaks: "Look, Mom! \
23 │ No \\n's!",
> 24 │ }
│ ^
> 25 │ ]
│ ^
26 │
i Use an array for a sequence of values: `[1, 2]`
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
source: crates/biome_formatter_test/src/snapshot_builder.rs
info: json/json5-as-json-with-trailing-commas/nested-quotes.json
---

# Input

```json
Expand Down Expand Up @@ -86,6 +85,19 @@ nested-quotes.json:4:5 parse ━━━━━━━━━━━━━━━━━
i Use double quotes to escape the string.
nested-quotes.json:4:18 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× End of file expected
2 │ "noSpace":true,
3 │ "quote": {
> 4'singleQuote': 'exa"mple',
^^^^^^^^^^^^^
5"indented": true,
6},
i Use an array for a sequence of values: `[1, 2]`
nested-quotes.json:4:20 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× JSON standard does not allow single quoted strings
Expand Down Expand Up @@ -234,5 +246,3 @@ nested-quotes.json:12:4 parse ━━━━━━━━━━━━━━━━
```


Loading

0 comments on commit 1abda0c

Please sign in to comment.