View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0000354 | file | General | public | 2022-06-06 21:37 | 2022-06-10 14:14 |
| Reporter | vinc17 | Assigned To | christos | ||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | resolved | Resolution | fixed | ||
| Product Version | 5.41 | ||||
| Fixed in Version | 5.43 | ||||
| Summary | 0000354: Fails to detect JSON in case of empty array with spaces | ||||
| Description | When a JSON file has an empty array with spaces between the brackets, it is misdetected as a text file. | ||||
| Steps To Reproduce | $ echo '{"a":[ ]}' | file - /dev/stdin: ASCII text | ||||
| Additional Information | This is due to a missing call to json_skip_space in function json_parse_array of src/is_json.c (see json_parse_object as a comparison). I've attached a patch with a testcase. | ||||
| Tags | No tags attached. | ||||
|
|
file-json-array.patch (1,189 bytes)
Description: Fails to detect JSON in case of empty array with spaces.
Author: Vincent Lefevre <vincent@vinc17.net>
Last-Update: 2022-06-06
diff --git a/src/is_json.c b/src/is_json.c
index c276b7be..36cccbdf 100644
--- a/src/is_json.c
+++ b/src/is_json.c
@@ -183,6 +183,7 @@ json_parse_array(const unsigned char **ucp, const unsigned char *ue,
DPRINTF("Parse array: ", uc, *ucp);
while (uc < ue) {
+ uc = json_skip_space(uc, ue);
if (*uc == ']')
goto done;
if (!json_parse(&uc, ue, st, lvl + 1))
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b17dfb12..4b2f4989 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -41,6 +41,8 @@ json4.result \
json4.testfile \
json5.result \
json5.testfile \
+json6.result \
+json6.testfile \
matilde.arm.result \
matilde.arm.testfile \
pcjr.result \
diff --git a/tests/json6.result b/tests/json6.result
new file mode 100644
index 00000000..550d7ac2
--- /dev/null
+++ b/tests/json6.result
@@ -0,0 +1 @@
+JSON text data
\ No newline at end of file
diff --git a/tests/json6.testfile b/tests/json6.testfile
new file mode 100644
index 00000000..db310f37
--- /dev/null
+++ b/tests/json6.testfile
@@ -0,0 +1 @@
+{"a":[ ]}
|
|
|
Committed, many thanks (and for providing the test case!). |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2022-06-06 21:37 | vinc17 | New Issue | |
| 2022-06-06 21:37 | vinc17 | File Added: file-json-array.patch | |
| 2022-06-10 14:14 | christos | Assigned To | => christos |
| 2022-06-10 14:14 | christos | Status | new => assigned |
| 2022-06-10 14:14 | christos | Status | assigned => resolved |
| 2022-06-10 14:14 | christos | Resolution | open => fixed |
| 2022-06-10 14:14 | christos | Fixed in Version | => 5.43 |
| 2022-06-10 14:14 | christos | Note Added: 0003760 |