Skip to content

Commit

Permalink
Report error on missing closing quote for quoted String
Browse files Browse the repository at this point in the history
  • Loading branch information
fabricereix committed Dec 10, 2021
1 parent 47170ee commit 165e790
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
6 changes: 6 additions & 0 deletions integration/tests_error_parser/missing_quote.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
error: Parsing literal
--> tests_error_parser/missing_quote.hurl:4:41
|
4 | jsonpath "$.error.message" == "not found
| ^ expecting '"'
|
1 change: 1 addition & 0 deletions integration/tests_error_parser/missing_quote.exit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
4 changes: 4 additions & 0 deletions integration/tests_error_parser/missing_quote.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POST http://localhost:8000/not-found
HTTP/1.1 404
[Asserts]
jsonpath "$.error.message" == "not found
20 changes: 20 additions & 0 deletions packages/hurl_core/src/parser/predicate_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
20 changes: 17 additions & 3 deletions packages/hurl_core/src/parser/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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("\"\"");
Expand Down

0 comments on commit 165e790

Please sign in to comment.