From 34d6fd48c36601e318c068dec3b53145146ba00d Mon Sep 17 00:00:00 2001 From: Ggiggle <47661277+Ggiggle@users.noreply.github.com> Date: Mon, 4 Nov 2024 11:53:03 +0800 Subject: [PATCH] fix(pilota-thrift-parser): trim extra whitespace characters at the end of annotation list item (#281) * fix(pilota-thrift-parser): trim extra whitespace characters at the end of annotation list * fix(pilota-thrift-parser): add the list end blank test case for annotation parser --- Cargo.lock | 2 +- pilota-thrift-parser/Cargo.toml | 2 +- pilota-thrift-parser/src/parser/annotation.rs | 9 +++++++++ pilota-thrift-parser/src/parser/mod.rs | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 35948945..e9c368eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -884,7 +884,7 @@ dependencies = [ [[package]] name = "pilota-thrift-parser" -version = "0.11.2" +version = "0.11.3" dependencies = [ "nom", ] diff --git a/pilota-thrift-parser/Cargo.toml b/pilota-thrift-parser/Cargo.toml index 5106bc7b..6d883452 100644 --- a/pilota-thrift-parser/Cargo.toml +++ b/pilota-thrift-parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pilota-thrift-parser" -version = "0.11.2" +version = "0.11.3" edition = "2021" description = "Pilota thrift Parser." documentation = "https://docs.rs/pilota" diff --git a/pilota-thrift-parser/src/parser/annotation.rs b/pilota-thrift-parser/src/parser/annotation.rs index a395c471..139226d8 100644 --- a/pilota-thrift-parser/src/parser/annotation.rs +++ b/pilota-thrift-parser/src/parser/annotation.rs @@ -51,5 +51,14 @@ mod tests { #[test] fn test_annotations() { let _a = Annotations::parse(r#"(go.tag = "json:\"Ids\" split:\"type=tenant\"")"#).unwrap(); + + let input = r#"( + cpp.type = "DenseFoo", + python.type = "DenseFoo", + java.final = "", + )"#; + let (remain, a) = Annotations::parse(input).unwrap(); + assert!(remain.is_empty()); + assert_eq!(a.len(), 3); } } diff --git a/pilota-thrift-parser/src/parser/mod.rs b/pilota-thrift-parser/src/parser/mod.rs index da1e5578..e14f0e2e 100644 --- a/pilota-thrift-parser/src/parser/mod.rs +++ b/pilota-thrift-parser/src/parser/mod.rs @@ -49,7 +49,7 @@ impl Parser for Path { } pub(crate) fn list_separator(input: &str) -> IResult<&str, char> { - one_of(",;")(input) + map(tuple((one_of(",;"), opt(blank))), |(sep, _)| sep)(input) } fn comment(input: &str) -> IResult<&str, &str> {