Merge pull request #5577 from cobaweel/issue-5576

Fix issue 5576 (regex matching bug in expr)
This commit is contained in:
Daniel Hofstetter 2023-11-23 17:57:45 +01:00 committed by GitHub
commit 97d30bd486
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -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])

View file

@ -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]