diff --git a/crates/jlabel-question/src/parse_position.rs b/crates/jlabel-question/src/parse_position.rs index cd4f5fc..19270c9 100644 --- a/crates/jlabel-question/src/parse_position.rs +++ b/crates/jlabel-question/src/parse_position.rs @@ -27,6 +27,9 @@ pub enum PositionError { /// The suffix (string after the range section) conflicts with the estimated position. #[error("Suffix has unknown sequence")] SuffixVerifyError, + /// An asterisk(s) was found in the range section. This implies the pattern matches across multiple fields. + #[error("Asterisk is not allowed in range section")] + AsteriskInRange, /// Range section is empty. This pattern does not match any label. #[error("Range is empty")] EmptyRange, @@ -153,6 +156,9 @@ impl<'a> PositionSplit<'a> { if self.range.is_empty() { return Err(PositionError::EmptyRange); } + if self.range.contains('*') { + return Err(PositionError::AsteriskInRange); + } Ok(self.range) } } @@ -352,6 +358,11 @@ mod tests { Err(PositionError::SuffixVerifyError) ); + assert_eq!( + estimate_position("*/A:0+*/B:+*"), + Err(PositionError::AsteriskInRange) + ); + assert_eq!( estimate_position("*/B :0+*"), Err(PositionError::NoMatchingPosition) diff --git a/crates/jlabel-question/src/tests.rs b/crates/jlabel-question/src/tests.rs index 984d377..f742ffa 100644 --- a/crates/jlabel-question/src/tests.rs +++ b/crates/jlabel-question/src/tests.rs @@ -86,6 +86,14 @@ fn parse_question_err() { AllQuestion::parse(&["*/A:0/B:*"]), Err(InvalidPosition(SuffixVerifyError)) ); + assert_eq!( + AllQuestion::parse(&["*^k-o+*"]), + Err(InvalidPosition(SuffixVerifyError)) + ); + assert_eq!( + AllQuestion::parse(&["*-N+*+1+*"]), + Err(InvalidPosition(AsteriskInRange)) + ); } #[test]