mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 14:07:46 +00:00
expr: fix panic for "empty substitution" test case
This commit is contained in:
parent
aa010b71b8
commit
0ba9a301b0
1 changed files with 11 additions and 1 deletions
|
@ -148,7 +148,7 @@ impl StringOp {
|
||||||
.map_err(|_| ExprError::InvalidRegexExpression)?;
|
.map_err(|_| ExprError::InvalidRegexExpression)?;
|
||||||
Ok(if re.captures_len() > 0 {
|
Ok(if re.captures_len() > 0 {
|
||||||
re.captures(&left)
|
re.captures(&left)
|
||||||
.map(|captures| captures.at(1).unwrap())
|
.and_then(|captures| captures.at(1))
|
||||||
.unwrap_or("")
|
.unwrap_or("")
|
||||||
.to_string()
|
.to_string()
|
||||||
} else {
|
} else {
|
||||||
|
@ -609,4 +609,14 @@ mod test {
|
||||||
Err(ExprError::ExpectedClosingBraceInsteadOf("a".to_string()))
|
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(), "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue