From 22d05bb3955f0577e0f7cf80bd605891d5f09a23 Mon Sep 17 00:00:00 2001 From: Clement Delafargue Date: Fri, 28 Jul 2023 17:22:32 +0200 Subject: [PATCH] fix: parse empty strings 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. --- biscuit-parser/src/parser.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/biscuit-parser/src/parser.rs b/biscuit-parser/src/parser.rs index e2134a78..392e46b3 100644 --- a/biscuit-parser/src/parser.rs +++ b/biscuit-parser/src/parser.rs @@ -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> { @@ -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))));