Skip to content

Commit

Permalink
Merge pull request uutils#5577 from cobaweel/issue-5576
Browse files Browse the repository at this point in the history
Fix issue 5576 (regex matching bug in expr)
  • Loading branch information
cakebaker committed Nov 23, 2023
2 parents 550f3b0 + 7efe331 commit 97d30bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/uu/expr/src/syntax_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ fn infix_operator_and(values: &[String]) -> String {

fn operator_match(values: &[String]) -> Result<String, String> {
assert!(values.len() == 2);
let re = Regex::with_options(&values[1], RegexOptions::REGEX_OPTION_NONE, Syntax::grep())
let re_string = format!("^{}", &values[1]);
let re = Regex::with_options(&re_string, RegexOptions::REGEX_OPTION_NONE, Syntax::grep())
.map_err(|err| err.description().to_string())?;
Ok(if re.captures_len() > 0 {
re.captures(&values[0])
Expand Down
4 changes: 4 additions & 0 deletions tests/by-util/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ fn test_regex() {
.args(&["-5", ":", "-\\{0,1\\}[0-9]*$"])
.succeeds()
.stdout_only("2\n");
new_ucmd!()
.args(&["abc", ":", "bc"])
.fails()
.stdout_only("0\n");
}

#[test]
Expand Down

0 comments on commit 97d30bd

Please sign in to comment.