Fix empty JSON key parsing

This commit is contained in:
Fabrice Reix 2024-06-24 21:29:40 +02:00
parent 15579a457b
commit 37d836388c
No known key found for this signature in database
GPG Key ID: BF5213154B2E7155
4 changed files with 6 additions and 10 deletions

View File

@ -1,4 +1,4 @@
curl --header 'Content-Type: application/json' --data $'{\n "name": "Bob",\n "password": "&secret\\\\\'<>",\n "age": 30,\n "strict": true,\n "spacing": "\\n",\n "g_clef": "\\uD834\\uDD1E",\n "items": [true, "true", 1],\n "variable": "\\\\"\n}' 'http://localhost:8000/post-json'
curl --header 'Content-Type: application/json' --data $'{\n "name": "Bob",\n "password": "&secret\\\\\'<>",\n "age": 30,\n "strict": true,\n "spacing": "\\n",\n "g_clef": "\\uD834\\uDD1E",\n "items": [true, "true", 1],\n "variable": "\\\\",\n "": "empty"\n}' 'http://localhost:8000/post-json'
curl --header 'Content-Type: application/json' --data '[1,2,3]' 'http://localhost:8000/post-json-array'
curl --header 'Content-Type: application/json' --data '[]' 'http://localhost:8000/post-json-array-empty'
curl --header 'Content-Type: application/json' --data '"Hello"' 'http://localhost:8000/post-json-string'

View File

@ -7,7 +7,8 @@ POST http://localhost:8000/post-json
"spacing": "\n",
"g_clef": "\uD834\uDD1E",
"items": [true, "true", 1],
"variable": "{{string_variable}}"
"variable": "{{string_variable}}",
"": "empty"
}
HTTP 200

View File

@ -16,7 +16,8 @@ def post_json():
"spacing": "\\n",
"g_clef": "\\uD834\\uDD1E",
"items": [true, \"true\", 1],
"variable": "\\\\"
"variable": "\\\\",
"": "empty"
}"""
)
return ""

View File

@ -363,14 +363,8 @@ pub fn object_value(reader: &mut Reader) -> ParseResult<JsonValue> {
}
fn key(reader: &mut Reader) -> ParseResult<Template> {
let save = reader.state;
let name = string_template(reader).map_err(|e| e.non_recoverable())?;
if name.elements.is_empty() {
let kind = ParseErrorKind::Json(JsonErrorVariant::EmptyElement);
Err(ParseError::new(save.pos, false, kind))
} else {
Ok(name)
}
Ok(name)
}
fn object_element(reader: &mut Reader) -> ParseResult<JsonObjectElement> {