1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-02 05:57:46 +00:00

expr: fix panic for "empty substitution" test case

This commit is contained in:
Joseph Jon Booker 2024-03-25 22:03:26 -05:00
parent aa010b71b8
commit 0ba9a301b0

View file

@ -148,7 +148,7 @@ impl StringOp {
.map_err(|_| ExprError::InvalidRegexExpression)?;
Ok(if re.captures_len() > 0 {
re.captures(&left)
.map(|captures| captures.at(1).unwrap())
.and_then(|captures| captures.at(1))
.unwrap_or("")
.to_string()
} else {
@ -609,4 +609,14 @@ mod test {
Err(ExprError::ExpectedClosingBraceInsteadOf("a".to_string()))
);
}
#[test]
fn empty_substitution() {
// causes a panic in 0.0.25
let result = AstNode::parse(&["a", ":", r"\(b\)*"])
.unwrap()
.eval()
.unwrap();
assert_eq!(result.eval_as_string(), "");
}
}