diff --git a/integration/tests_ok/post_json.html b/integration/tests_ok/post_json.html
index 618fb5cb6..cc85b3fda 100644
--- a/integration/tests_ok/post_json.html
+++ b/integration/tests_ok/post_json.html
@@ -18,6 +18,12 @@
HTTP 200
+
+POST http://localhost:8000/post-json-array-empty
+[]
+
+HTTP 200
+
POST http://localhost:8000/post-json-string
"Hello"
diff --git a/integration/tests_ok/post_json.hurl b/integration/tests_ok/post_json.hurl
index f38dee9f2..23523144d 100644
--- a/integration/tests_ok/post_json.hurl
+++ b/integration/tests_ok/post_json.hurl
@@ -18,6 +18,12 @@ POST http://localhost:8000/post-json-array
HTTP 200
+
+POST http://localhost:8000/post-json-array-empty
+[]
+
+HTTP 200
+
POST http://localhost:8000/post-json-string
"Hello"
diff --git a/integration/tests_ok/post_json.json b/integration/tests_ok/post_json.json
index 5380e7b52..f036be166 100644
--- a/integration/tests_ok/post_json.json
+++ b/integration/tests_ok/post_json.json
@@ -1 +1 @@
-{"entries":[{"request":{"method":"POST","url":"http://localhost:8000/post-json","body":{"type":"json","value":{"name":"Bob","password":"&secret\\'<>","age":30,"strict":true,"spacing":"\n","g_clef":"ƻǿ","items":[true,"true",1],"variable":"{{string_variable}}"}}},"response":{"status":200}},{"request":{"method":"POST","url":"http://localhost:8000/post-json-array","body":{"type":"json","value":[1,2,3]}},"response":{"status":200}},{"request":{"method":"POST","url":"http://localhost:8000/post-json-string","body":{"type":"json","value":"Hello"}},"response":{"status":200}},{"request":{"method":"POST","url":"http://localhost:8000/post-json-number","body":{"type":"json","value":100}},"response":{"status":200}},{"request":{"method":"POST","url":"http://localhost:8000/post-json-numbers","body":{"type":"json","value":{"natural":100,"negative":-1,"float":"3.333333333333333","exponent":100e100}}},"response":{"status":200}},{"request":{"method":"POST","url":"http://localhost:8000/post-json-boolean","body":{"type":"json","value":true}},"response":{"status":200}},{"request":{"method":"GET","url":"http://localhost:8000/get-name"},"response":{"status":200,"captures":[{"name":"name","query":{"type":"body"}}]}},{"request":{"method":"POST","url":"http://localhost:8000/check_name","body":{"type":"json","value":{"name":"{{name}}"}}}}]}
+{"entries":[{"request":{"method":"POST","url":"http://localhost:8000/post-json","body":{"type":"json","value":{"name":"Bob","password":"&secret\\'<>","age":30,"strict":true,"spacing":"\n","g_clef":"ƻǿ","items":[true,"true",1],"variable":"{{string_variable}}"}}},"response":{"status":200}},{"request":{"method":"POST","url":"http://localhost:8000/post-json-array","body":{"type":"json","value":[1,2,3]}},"response":{"status":200}},{"request":{"method":"POST","url":"http://localhost:8000/post-json-array-empty","body":{"type":"json","value":[]}},"response":{"status":200}},{"request":{"method":"POST","url":"http://localhost:8000/post-json-string","body":{"type":"json","value":"Hello"}},"response":{"status":200}},{"request":{"method":"POST","url":"http://localhost:8000/post-json-number","body":{"type":"json","value":100}},"response":{"status":200}},{"request":{"method":"POST","url":"http://localhost:8000/post-json-numbers","body":{"type":"json","value":{"natural":100,"negative":-1,"float":"3.333333333333333","exponent":100e100}}},"response":{"status":200}},{"request":{"method":"POST","url":"http://localhost:8000/post-json-boolean","body":{"type":"json","value":true}},"response":{"status":200}},{"request":{"method":"GET","url":"http://localhost:8000/get-name"},"response":{"status":200,"captures":[{"name":"name","query":{"type":"body"}}]}},{"request":{"method":"POST","url":"http://localhost:8000/check_name","body":{"type":"json","value":{"name":"{{name}}"}}}}]}
diff --git a/integration/tests_ok/post_json.py b/integration/tests_ok/post_json.py
index ac66c57a2..2008c1941 100644
--- a/integration/tests_ok/post_json.py
+++ b/integration/tests_ok/post_json.py
@@ -31,6 +31,14 @@ def post_json_array():
return ""
+@app.route("/post-json-array-empty", methods=["POST"])
+def post_json_array_empty():
+ assert request.headers["Content-Type"] == "application/json"
+ s = request.data.decode("utf-8")
+ assert s == "[]"
+ return ""
+
+
@app.route("/post-json-string", methods=["POST"])
def post_json_string():
assert request.headers["Content-Type"] == "application/json"
diff --git a/packages/hurl_core/src/parser/sections.rs b/packages/hurl_core/src/parser/sections.rs
index eaa5759a9..fc3fc83a0 100644
--- a/packages/hurl_core/src/parser/sections.rs
+++ b/packages/hurl_core/src/parser/sections.rs
@@ -109,8 +109,19 @@ fn response_section(reader: &mut Reader) -> ParseResult<'static, Section> {
}
fn section_name(reader: &mut Reader) -> ParseResult<'static, String> {
+ let pos = reader.state.pos.clone();
try_literal("[", reader)?;
let name = reader.read_while(|c| c.is_alphanumeric());
+ if name.is_empty() {
+ // Could be the empty json array for the body
+ return Err(Error {
+ pos,
+ recoverable: true,
+ inner: ParseError::Expecting {
+ value: "a valid section name".to_string(),
+ },
+ });
+ }
try_literal("]", reader)?;
Ok(name)
}
@@ -729,6 +740,9 @@ mod tests {
fn test_section_name() {
let mut reader = Reader::init("[SectionA]");
assert_eq!(section_name(&mut reader).unwrap(), String::from("SectionA"));
+
+ let mut reader = Reader::init("[]");
+ assert!(section_name(&mut reader).err().unwrap().recoverable);
}
#[test]