mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Fix issue 5576 (regex matching bug in expr)
Issue 5576 reported a bug in expr, found by the fuzzer. The problem turns out to be with the regex match operator `:`, which is defined in POSIX and the GNU manual to match the pattern only when it occurs at the beginning of the string, i.e., the regex has an implicit `^` prepended to it. We hadn't been doing that.
This commit is contained in:
parent
fff1302bdf
commit
7efe33108a
2 changed files with 6 additions and 1 deletions
|
@ -498,7 +498,8 @@ fn infix_operator_and(values: &[String]) -> String {
|
||||||
|
|
||||||
fn operator_match(values: &[String]) -> Result<String, String> {
|
fn operator_match(values: &[String]) -> Result<String, String> {
|
||||||
assert!(values.len() == 2);
|
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())?;
|
.map_err(|err| err.description().to_string())?;
|
||||||
Ok(if re.captures_len() > 0 {
|
Ok(if re.captures_len() > 0 {
|
||||||
re.captures(&values[0])
|
re.captures(&values[0])
|
||||||
|
|
|
@ -289,6 +289,10 @@ fn test_regex() {
|
||||||
.args(&["-5", ":", "-\\{0,1\\}[0-9]*$"])
|
.args(&["-5", ":", "-\\{0,1\\}[0-9]*$"])
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only("2\n");
|
.stdout_only("2\n");
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["abc", ":", "bc"])
|
||||||
|
.fails()
|
||||||
|
.stdout_only("0\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue