mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2025-01-08 20:54:28 +03:00
Fix key-string parser
This commit is contained in:
parent
6b7753e174
commit
bb7cf25a57
@ -319,7 +319,7 @@ key-string: (key-string-content | template)+
|
||||
|
||||
key-string-content: (key-string-text | key-string-escaped-char)*
|
||||
|
||||
key-string-text: ~[#: \n\r\t\\]+
|
||||
key-string-text: (alphanum | "_" | "-" | "." | "[" | "]" | "@" | "$") +
|
||||
|
||||
key-string-escaped-char: "\\" ("#" | ":" | "\\" | "\b" | "\f" | "\n" | "\r" | "\t" | "\u" unicode-char )
|
||||
|
||||
@ -418,7 +418,9 @@ filter:
|
||||
| count-filter
|
||||
| url-encode-filter
|
||||
| url-decode-filter
|
||||
| to-int
|
||||
| html-encode-filter
|
||||
| html-decode-filter
|
||||
| to-int-filter
|
||||
|
||||
regex-filter: "regex" sp (quoted-string | regex)
|
||||
|
||||
@ -432,7 +434,7 @@ html-encode-filter: "htmlEscape"
|
||||
|
||||
html-decode-filter: "htmlUnescape"
|
||||
|
||||
to-int: "toInt"
|
||||
to-int-filter: "toInt"
|
||||
|
||||
# Lexical Grammar
|
||||
|
||||
@ -440,6 +442,8 @@ boolean: "true" | "false"
|
||||
|
||||
null: "null"
|
||||
|
||||
alphanum: [A-Za-z0-9]
|
||||
|
||||
integer: digit+
|
||||
|
||||
float: integer fraction
|
||||
|
@ -96,12 +96,20 @@ pub fn unquoted_string_key(reader: &mut Reader) -> ParseResult<'static, EncodedS
|
||||
match reader.read() {
|
||||
None => break,
|
||||
Some(c) => {
|
||||
if ['#', ':', ' ', '\n', '\r', '\n', '\t', '\\'].contains(&c) {
|
||||
reader.state = save;
|
||||
break;
|
||||
} else {
|
||||
if c.is_alphanumeric()
|
||||
|| c == '_'
|
||||
|| c == '-'
|
||||
|| c == '.'
|
||||
|| c == '['
|
||||
|| c == ']'
|
||||
|| c == '@'
|
||||
|| c == '$'
|
||||
{
|
||||
value.push(c);
|
||||
encoded.push_str(reader.from(save.cursor).as_str())
|
||||
} else {
|
||||
reader.state = save;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -554,6 +562,16 @@ mod tests {
|
||||
let error = unquoted_string_key(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 2 });
|
||||
assert_eq!(error.inner, ParseError::EscapeChar {});
|
||||
|
||||
let mut reader = Reader::init(r#"{"id":1}"#);
|
||||
let error = unquoted_string_key(&mut reader).err().unwrap();
|
||||
assert_eq!(error.pos, Pos { line: 1, column: 1 });
|
||||
assert_eq!(
|
||||
error.inner,
|
||||
ParseError::Expecting {
|
||||
value: "key string".to_string()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user