mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-12-26 20:42:01 +03:00
Fix Parsing / compliant with grammar
This commit is contained in:
parent
44f43bcf73
commit
3eaa74ce11
@ -319,7 +319,7 @@ key-string: (key-string-content | template)+
|
||||
|
||||
key-string-content: (key-string-text | key-string-escaped-char)*
|
||||
|
||||
key-string-text: ~[#:\n\\]+
|
||||
key-string-text: ~[#: \n\r\t\\]+
|
||||
|
||||
key-string-escaped-char: "\\" ("#" | ":" | "\\" | "\b" | "\f" | "\n" | "\r" | "\t" | "\u" unicode-char )
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3'
|
||||
curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3db¶m4=1,2,3'
|
||||
curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3'
|
||||
curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3&$top=5'
|
||||
curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3db¶m4=1,2,3&$top=5'
|
||||
curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3&$top=5'
|
||||
curl 'http://localhost:8000/querystring-params-encoded?value1=/&value2=%2F&value3=%2F'
|
||||
|
@ -4,11 +4,12 @@
|
||||
<span class="line"><span class="string">param2</span><span>:</span><span class="string"></span></span>
|
||||
<span class="line"><span class="string">param3</span><span>:</span> <span class="string">a=b</span></span>
|
||||
<span class="line"><span class="string">param4</span><span>:</span> <span class="string">1,2,3</span></span>
|
||||
<span class="line"><span class="string">$top</span><span>:</span> <span class="string">5</span></span>
|
||||
</span><span class="response"><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><span class="comment"># same version as raw</span>
|
||||
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/querystring-params?param1=value1&param2=&param3=a%3db&param4=1,2,3</span></span>
|
||||
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/querystring-params?param1=value1&param2=&param3=a%3db&param4=1,2,3&$top=5</span></span>
|
||||
</span><span class="response"><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>
|
||||
@ -18,6 +19,7 @@
|
||||
<span class="line"><span class="string">param2</span><span>:</span><span class="string"></span></span>
|
||||
<span class="line"><span class="string">param3</span><span>:</span> <span class="string">a=b</span></span>
|
||||
<span class="line"><span class="string">param4</span><span>:</span> <span class="string">1,2,3</span></span>
|
||||
<span class="line"><span class="string">$top</span><span>:</span><span class="string">5</span></span>
|
||||
</span><span class="response"><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>
|
||||
|
@ -4,11 +4,12 @@ param1: value1
|
||||
param2:
|
||||
param3: a=b
|
||||
param4: 1,2,3
|
||||
$top: 5
|
||||
HTTP 200
|
||||
|
||||
|
||||
# same version as raw
|
||||
GET http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3db¶m4=1,2,3
|
||||
GET http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3db¶m4=1,2,3&$top=5
|
||||
HTTP 200
|
||||
|
||||
|
||||
@ -18,6 +19,7 @@ GET http://localhost:8000/querystring-params?param1=value1
|
||||
param2:
|
||||
param3: a=b
|
||||
param4: 1,2,3
|
||||
$top:5
|
||||
HTTP 200
|
||||
|
||||
|
||||
|
@ -1 +1 @@
|
||||
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/querystring-params","query_string_params":[{"name":"param1","value":"value1"},{"name":"param2","value":""},{"name":"param3","value":"a=b"},{"name":"param4","value":"1,2,3"}]},"response":{"status":200}},{"request":{"method":"GET","url":"http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3db¶m4=1,2,3"},"response":{"status":200}},{"request":{"method":"GET","url":"http://localhost:8000/querystring-params?param1=value1","query_string_params":[{"name":"param2","value":""},{"name":"param3","value":"a=b"},{"name":"param4","value":"1,2,3"}]},"response":{"status":200}},{"request":{"method":"GET","url":"http://localhost:8000/querystring-params-encoded?value1=/&value2=%2F","query_string_params":[{"name":"value3","value":"/"}]},"response":{"status":200}}]}
|
||||
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/querystring-params","query_string_params":[{"name":"param1","value":"value1"},{"name":"param2","value":""},{"name":"param3","value":"a=b"},{"name":"param4","value":"1,2,3"},{"name":"$top","value":"5"}]},"response":{"status":200}},{"request":{"method":"GET","url":"http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3db¶m4=1,2,3&$top=5"},"response":{"status":200}},{"request":{"method":"GET","url":"http://localhost:8000/querystring-params?param1=value1","query_string_params":[{"name":"param2","value":""},{"name":"param3","value":"a=b"},{"name":"param4","value":"1,2,3"},{"name":"$top","value":"5"}]},"response":{"status":200}},{"request":{"method":"GET","url":"http://localhost:8000/querystring-params-encoded?value1=/&value2=%2F","query_string_params":[{"name":"value3","value":"/"}]},"response":{"status":200}}]}
|
||||
|
@ -8,6 +8,7 @@ def querystring_params():
|
||||
assert request.args.get("param2") == ""
|
||||
assert request.args.get("param3") == "a=b"
|
||||
assert request.args.get("param4") == "1,2,3"
|
||||
assert request.args.get("$top") == "5"
|
||||
return ""
|
||||
|
||||
|
||||
|
@ -260,6 +260,10 @@ fn test_querystring_params() {
|
||||
name: "param4".to_string(),
|
||||
value: "1,2,3".to_string(),
|
||||
},
|
||||
Param {
|
||||
name: "$top".to_string(),
|
||||
value: "5".to_string(),
|
||||
},
|
||||
],
|
||||
form: vec![],
|
||||
multipart: vec![],
|
||||
@ -269,11 +273,11 @@ fn test_querystring_params() {
|
||||
};
|
||||
assert_eq!(
|
||||
client.curl_command_line(&request_spec, &context_dir, &options),
|
||||
"curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3'".to_string()
|
||||
"curl 'http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3&$top=5'".to_string()
|
||||
);
|
||||
let (request, response) = client.execute(&request_spec, &options, &logger).unwrap();
|
||||
assert_eq!(request.method, "GET".to_string());
|
||||
assert_eq!(request.url, "http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3".to_string());
|
||||
assert_eq!(request.url, "http://localhost:8000/querystring-params?param1=value1¶m2=¶m3=a%3Db¶m4=1%2C2%2C3&$top=5".to_string());
|
||||
assert_eq!(request.headers.len(), 3);
|
||||
|
||||
assert_eq!(response.status, 200);
|
||||
|
@ -97,19 +97,12 @@ pub fn unquoted_string_key(reader: &mut Reader) -> ParseResult<'static, EncodedS
|
||||
match reader.read() {
|
||||
None => break,
|
||||
Some(c) => {
|
||||
if c.is_alphanumeric()
|
||||
|| c == '_'
|
||||
|| c == '-'
|
||||
|| c == '.'
|
||||
|| c == '['
|
||||
|| c == ']'
|
||||
|| c == '@'
|
||||
{
|
||||
value.push(c);
|
||||
encoded.push_str(reader.from(save.cursor).as_str())
|
||||
} else {
|
||||
if ['#', ':', ' ', '\n', '\r', '\n', '\t', '\\'].contains(&c) {
|
||||
reader.state = save;
|
||||
break;
|
||||
} else {
|
||||
value.push(c);
|
||||
encoded.push_str(reader.from(save.cursor).as_str())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -451,6 +444,18 @@ mod tests {
|
||||
}
|
||||
);
|
||||
assert_eq!(reader.state.cursor, 15);
|
||||
|
||||
let mut reader = Reader::init("$top:");
|
||||
assert_eq!(
|
||||
unquoted_string_key(&mut reader).unwrap(),
|
||||
EncodedString {
|
||||
value: "$top".to_string(),
|
||||
encoded: "$top".to_string(),
|
||||
quotes: false,
|
||||
source_info: SourceInfo::new(1, 1, 1, 5),
|
||||
}
|
||||
);
|
||||
assert_eq!(reader.state.cursor, 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user