mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-11-28 04:13:33 +03:00
Merge pull request #183 from Orange-OpenSource/fix/parsing-quote-in-value
Fix parsing quote in quoted template
This commit is contained in:
commit
c0600b720c
@ -1 +1 @@
|
||||
<div class="hurl-file"><div class="hurl-entry"><div class="request"><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/assert-header</span></span></div><div class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="status">200</span></span><span class="line"><span class="string">Content-Type</span><span>:</span> <span class="string">text/html; charset=utf-8</span></span><span class="line"><span class="string">Set-Cookie</span><span>:</span> <span class="string">cookie1=value1; Path=/</span></span><span class="line"><span class="string">Set-Cookie</span><span>:</span> <span class="string">cookie2=value2; Path=/</span></span><span class="line section-header">[Asserts]</span></span><span class="line"><span class="query-type">header</span> <span class="string">"Custom"</span> not <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">header</span> <span class="string">"Content-Type"</span> <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">header</span> <span class="string">"Header1"</span> <span class="predicate-type">equals</span> <span class="string">"value1"</span></span><span class="line"><span class="query-type">header</span> <span class="string">"Set-Cookie"</span> <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">header</span> <span class="string">"Set-Cookie"</span> <span class="predicate-type">equals</span> <span class="number">3</span></span><span class="line"><span class="query-type">header</span> <span class="string">"Set-Cookie"</span> <span class="predicate-type">includes</span> <span class="string">"cookie1=value1; Path=/"</span></span><span class="line"><span class="query-type">header</span> <span class="string">"Set-Cookie"</span> not <span class="predicate-type">includes</span> <span class="string">"cookie4=value4; Path=/"</span></span></div></div></div>
|
||||
<div class="hurl-file"><div class="hurl-entry"><div class="request"><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/assert-header</span></span></div><div class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="status">200</span></span><span class="line"><span class="string">Content-Type</span><span>:</span> <span class="string">text/html; charset=utf-8</span></span><span class="line"><span class="string">Set-Cookie</span><span>:</span> <span class="string">cookie1=value1; Path=/</span></span><span class="line"><span class="string">Set-Cookie</span><span>:</span> <span class="string">cookie2=value2; Path=/</span></span><span class="line section-header">[Asserts]</span></span><span class="line"><span class="query-type">header</span> <span class="string">"Custom"</span> not <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">header</span> <span class="string">"Content-Type"</span> <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">header</span> <span class="string">"Header1"</span> <span class="predicate-type">equals</span> <span class="string">"value1"</span></span><span class="line"><span class="query-type">header</span> <span class="string">"ETag"</span> <span class="predicate-type">equals</span> <span class="string">""33a64df551425fcc55e4d42a148795d9f25f89d4""</span></span><span class="line"><span class="query-type">header</span> <span class="string">"Set-Cookie"</span> <span class="predicate-type">exists</span></span><span class="line"><span class="query-type">header</span> <span class="string">"Set-Cookie"</span> <span class="predicate-type">equals</span> <span class="number">3</span></span><span class="line"><span class="query-type">header</span> <span class="string">"Set-Cookie"</span> <span class="predicate-type">includes</span> <span class="string">"cookie1=value1; Path=/"</span></span><span class="line"><span class="query-type">header</span> <span class="string">"Set-Cookie"</span> not <span class="predicate-type">includes</span> <span class="string">"cookie4=value4; Path=/"</span></span></div></div></div>
|
@ -7,6 +7,7 @@ Set-Cookie: cookie2=value2; Path=/
|
||||
header "Custom" not exists
|
||||
header "Content-Type" exists
|
||||
header "Header1" equals "value1"
|
||||
header "ETag" equals "\"33a64df551425fcc55e4d42a148795d9f25f89d4\""
|
||||
header "Set-Cookie" exists
|
||||
header "Set-Cookie" countEquals 3
|
||||
header "Set-Cookie" includes "cookie1=value1; Path=/"
|
||||
|
@ -1 +1 @@
|
||||
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/assert-header"},"response":{"version":"HTTP/1.0","status":200,"headers":[{"name":"Content-Type","value":"text/html; charset=utf-8"},{"name":"Set-Cookie","value":"cookie1=value1; Path=/"},{"name":"Set-Cookie","value":"cookie2=value2; Path=/"}],"asserts":[{"query":{"type":"header","name":"Custom"},"predicate":{"not":true,"type":"exist"}},{"query":{"type":"header","name":"Content-Type"},"predicate":{"type":"exist"}},{"query":{"type":"header","name":"Header1"},"predicate":{"type":"equal","value":"value1"}},{"query":{"type":"header","name":"Set-Cookie"},"predicate":{"type":"exist"}},{"query":{"type":"header","name":"Set-Cookie"},"predicate":{"type":"count","value":3}},{"query":{"type":"header","name":"Set-Cookie"},"predicate":{"type":"include","value":"cookie1=value1; Path=/"}},{"query":{"type":"header","name":"Set-Cookie"},"predicate":{"not":true,"type":"include","value":"cookie4=value4; Path=/"}}]}}]}
|
||||
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/assert-header"},"response":{"version":"HTTP/1.0","status":200,"headers":[{"name":"Content-Type","value":"text/html; charset=utf-8"},{"name":"Set-Cookie","value":"cookie1=value1; Path=/"},{"name":"Set-Cookie","value":"cookie2=value2; Path=/"}],"asserts":[{"query":{"type":"header","name":"Custom"},"predicate":{"not":true,"type":"exist"}},{"query":{"type":"header","name":"Content-Type"},"predicate":{"type":"exist"}},{"query":{"type":"header","name":"Header1"},"predicate":{"type":"equal","value":"value1"}},{"query":{"type":"header","name":"ETag"},"predicate":{"type":"equal","value":"\"33a64df551425fcc55e4d42a148795d9f25f89d4\""}},{"query":{"type":"header","name":"Set-Cookie"},"predicate":{"type":"exist"}},{"query":{"type":"header","name":"Set-Cookie"},"predicate":{"type":"count","value":3}},{"query":{"type":"header","name":"Set-Cookie"},"predicate":{"type":"include","value":"cookie1=value1; Path=/"}},{"query":{"type":"header","name":"Set-Cookie"},"predicate":{"not":true,"type":"include","value":"cookie4=value4; Path=/"}}]}}]}
|
@ -5,6 +5,7 @@ from flask import make_response
|
||||
def assert_header():
|
||||
resp = make_response()
|
||||
resp.headers['Header1'] = 'value1'
|
||||
resp.headers['ETag'] = '"33a64df551425fcc55e4d42a148795d9f25f89d4"'
|
||||
resp.set_cookie('cookie1', 'value1')
|
||||
resp.set_cookie('cookie2', 'value2')
|
||||
resp.set_cookie('cookie3', 'value3')
|
||||
|
@ -152,7 +152,7 @@ pub fn quoted_template(reader: &mut Reader) -> ParseResult<'static, Template> {
|
||||
let mut chars = vec![];
|
||||
loop {
|
||||
let pos = reader.state.pos.clone();
|
||||
match any_char(vec![], reader) {
|
||||
match any_char(vec!['"'], reader) {
|
||||
Err(e) => {
|
||||
if e.recoverable {
|
||||
break;
|
||||
@ -160,8 +160,10 @@ pub fn quoted_template(reader: &mut Reader) -> ParseResult<'static, Template> {
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
Ok(('"', _)) => break,
|
||||
Ok((c, s)) => {
|
||||
if s == "\"" {
|
||||
break;
|
||||
}
|
||||
chars.push((c, s, pos));
|
||||
end = reader.state.clone().pos;
|
||||
}
|
||||
@ -339,6 +341,23 @@ mod tests {
|
||||
assert_eq!(reader.state.cursor, 7);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unquoted_template_with_quote() {
|
||||
let mut reader = Reader::init("\"hi\"");
|
||||
assert_eq!(
|
||||
unquoted_template(&mut reader).unwrap(),
|
||||
Template {
|
||||
quotes: false,
|
||||
elements: vec![TemplateElement::String {
|
||||
value: "\"hi\"".to_string(),
|
||||
encoded: "\"hi\"".to_string(),
|
||||
}],
|
||||
source_info: SourceInfo::init(1, 1, 1, 5),
|
||||
}
|
||||
);
|
||||
assert_eq!(reader.state.cursor, 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unquoted_template_hello_world() {
|
||||
let mut reader = Reader::init("hello\\u{20}{{name}}!");
|
||||
@ -487,6 +506,24 @@ mod tests {
|
||||
assert_eq!(reader.state.cursor, 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_quoted_template_with_quote() {
|
||||
// "\"hi\""
|
||||
let mut reader = Reader::init("\"\\\"hi\\\"\"");
|
||||
assert_eq!(
|
||||
quoted_template(&mut reader).unwrap(),
|
||||
Template {
|
||||
quotes: true,
|
||||
elements: vec![TemplateElement::String {
|
||||
value: "\"hi\"".to_string(),
|
||||
encoded: "\\\"hi\\\"".to_string()
|
||||
}],
|
||||
source_info: SourceInfo::init(1, 1, 1, 9),
|
||||
}
|
||||
);
|
||||
assert_eq!(reader.state.cursor, 8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_quoted_string() {
|
||||
let mut reader = Reader::init("\"\"");
|
||||
@ -529,6 +566,16 @@ mod tests {
|
||||
assert_eq!(reader.state.cursor, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_any_char_quote() {
|
||||
let mut reader = Reader::init("\\\"");
|
||||
assert_eq!(
|
||||
any_char(vec![], &mut reader).unwrap(),
|
||||
('"', "\\\"".to_string())
|
||||
);
|
||||
assert_eq!(reader.state.cursor, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_any_char_error() {
|
||||
let mut reader = Reader::init("");
|
||||
|
Loading…
Reference in New Issue
Block a user