Fix Parsing / compliant with grammar

This commit is contained in:
Fabrice Reix 2022-12-01 13:28:08 +01:00
parent 44f43bcf73
commit 3eaa74ce11
No known key found for this signature in database
GPG Key ID: 8D3D9DBDD96B2D30
8 changed files with 34 additions and 20 deletions

View File

@ -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 )

View File

@ -1,4 +1,4 @@
curl 'http://localhost:8000/querystring-params?param1=value1&param2=&param3=a%3Db&param4=1%2C2%2C3'
curl 'http://localhost:8000/querystring-params?param1=value1&param2=&param3=a%3db&param4=1,2,3'
curl 'http://localhost:8000/querystring-params?param1=value1&param2=&param3=a%3Db&param4=1%2C2%2C3'
curl 'http://localhost:8000/querystring-params?param1=value1&param2=&param3=a%3Db&param4=1%2C2%2C3&$top=5'
curl 'http://localhost:8000/querystring-params?param1=value1&param2=&param3=a%3db&param4=1,2,3&$top=5'
curl 'http://localhost:8000/querystring-params?param1=value1&param2=&param3=a%3Db&param4=1%2C2%2C3&$top=5'
curl 'http://localhost:8000/querystring-params-encoded?value1=/&value2=%2F&value3=%2F'

View File

@ -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&amp;param2=&amp;param3=a%3db&amp;param4=1,2,3</span></span>
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/querystring-params?param1=value1&amp;param2=&amp;param3=a%3db&amp;param4=1,2,3&amp;$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>

View File

@ -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&param2=&param3=a%3db&param4=1,2,3
GET http://localhost:8000/querystring-params?param1=value1&param2=&param3=a%3db&param4=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

View File

@ -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&param2=&param3=a%3db&param4=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&param2=&param3=a%3db&param4=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}}]}

View File

@ -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 ""

View File

@ -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&param2=&param3=a%3Db&param4=1%2C2%2C3'".to_string()
"curl 'http://localhost:8000/querystring-params?param1=value1&param2=&param3=a%3Db&param4=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&param2=&param3=a%3Db&param4=1%2C2%2C3".to_string());
assert_eq!(request.url, "http://localhost:8000/querystring-params?param1=value1&param2=&param3=a%3Db&param4=1%2C2%2C3&$top=5".to_string());
assert_eq!(request.headers.len(), 3);
assert_eq!(response.status, 200);

View File

@ -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]