mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-09-21 18:57:33 +03:00
Parse empty JSON array
This commit is contained in:
parent
a818624ab5
commit
798d87979c
@ -18,6 +18,12 @@
|
||||
</span><span class="response"><span class="line"></span>
|
||||
<span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
|
||||
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
|
||||
<span class="line"></span>
|
||||
<span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/post-json-array-empty</span></span>
|
||||
<span class="json"><span class="line">[]</span></span>
|
||||
</span><span class="response"><span class="line"></span>
|
||||
<span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
|
||||
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
|
||||
<span class="line"><span class="method">POST</span> <span class="url">http://localhost:8000/post-json-string</span></span>
|
||||
<span class="json"><span class="line">"Hello"</span></span>
|
||||
</span><span class="response"><span class="line"></span>
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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}}"}}}}]}
|
||||
|
@ -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"
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user