Skip to content

Commit

Permalink
fix: parse empty strings
Browse files Browse the repository at this point in the history
parse_string_internal, based on nom's escaped_transform only parsed strings with at least one character. I think escaped_transform itself is buggy, but it was faster to special case empty-strings in the biscuit grammar itself.
  • Loading branch information
divarvel committed Jul 28, 2023
1 parent f86329a commit 22d05bb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion biscuit-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,10 @@ fn parse_string_internal(i: &str) -> IResult<&str, String, Error> {
}

fn parse_string(i: &str) -> IResult<&str, String, Error> {
delimited(char('"'), parse_string_internal, char('"'))(i)
alt((
value("".to_string(), tag("\"\"")),
delimited(char('"'), parse_string_internal, char('"')),
))(i)
}

fn string(i: &str) -> IResult<&str, builder::Term, Error> {
Expand Down Expand Up @@ -1195,6 +1198,11 @@ mod tests {
);
}

#[test]
fn empty_string() {
assert_eq!(super::string("\"\""), Ok(("", builder::string(""))));
}

#[test]
fn integer() {
assert_eq!(super::integer("123"), Ok(("", builder::int(123))));
Expand Down

0 comments on commit 22d05bb

Please sign in to comment.