Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report error on missing closing quote for quoted String #407

Merged
merged 1 commit into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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