Report error on missing closing quote for quoted String

This commit is contained in:
Fabrice Reix 2021-12-10 08:42:05 +01:00 committed by Fabrice Reix
parent 47170ee4d5
commit 165e79054e
5 changed files with 48 additions and 3 deletions

View File

@ -0,0 +1,6 @@
error: Parsing literal
--> tests_error_parser/missing_quote.hurl:4:41
|
4 | jsonpath "$.error.message" == "not found
| ^ expecting '"'
|

View File

@ -0,0 +1 @@
2

View File

@ -0,0 +1,4 @@
POST http://localhost:8000/not-found
HTTP/1.1 404
[Asserts]
jsonpath "$.error.message" == "not found

View File

@ -117,4 +117,24 @@ mod tests {
assert_eq!(error.inner, ParseError::PredicateValue {});
assert!(!error.recoverable);
}
#[test]
fn test_predicate_value_error_missing_quote() {
let mut reader = Reader::init("\"not_found");
let error = predicate_value(&mut reader).err().unwrap();
assert_eq!(
error.pos,
Pos {
line: 1,
column: 11
}
);
assert_eq!(
error.inner,
ParseError::Expecting {
value: "\"".to_string()
}
);
assert!(!error.recoverable);
}
}

View File

@ -152,23 +152,23 @@ pub fn quoted_template(reader: &mut Reader) -> ParseResult<'static, Template> {
let mut chars = vec![];
loop {
let pos = reader.state.pos.clone();
let save = reader.state.clone();
match any_char(vec!['"'], reader) {
Err(e) => {
if e.recoverable {
reader.state = save;
break;
} else {
return Err(e);
}
}
Ok((c, s)) => {
if s == "\"" {
break;
}
chars.push((c, s, pos));
end = reader.state.clone().pos;
}
}
}
literal("\"", reader)?;
let encoded_string = template::EncodedString {
source_info: SourceInfo {
start: start.clone(),
@ -524,6 +524,20 @@ mod tests {
assert_eq!(reader.state.cursor, 8);
}
#[test]
fn test_quoted_template_error_missing_closing_quote() {
let mut reader = Reader::init("\"not found");
let error = quoted_template(&mut reader).err().unwrap();
assert_eq!(
error.pos,
Pos {
line: 1,
column: 11
}
);
assert!(!error.recoverable);
}
#[test]
fn test_quoted_string() {
let mut reader = Reader::init("\"\"");