From 8cd51227c61ddd40d94f38e4fb5022654382f0bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teemu=20P=C3=A4tsi?= Date: Sat, 26 Apr 2025 18:22:22 +0300 Subject: [PATCH 1/2] expr: Fix regex anchor matching behavior with `REGEX_OPTION_SINGLELINE` The previously used `REGEX_OPTION_NONE` allowed anchors (^) and ($) to match across newlines. New anchor behaviors: - `^` matches the start of the entire string (`\A`) - `$` matches the end of the entire string (`\Z`) --- src/uu/expr/src/syntax_tree.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/expr/src/syntax_tree.rs b/src/uu/expr/src/syntax_tree.rs index ac418cafeee..e6a5b347239 100644 --- a/src/uu/expr/src/syntax_tree.rs +++ b/src/uu/expr/src/syntax_tree.rs @@ -154,7 +154,7 @@ impl StringOp { let re_string = format!("{prefix}{right}"); let re = Regex::with_options( &re_string, - RegexOptions::REGEX_OPTION_NONE, + RegexOptions::REGEX_OPTION_SINGLELINE, Syntax::grep(), ) .map_err(|_| ExprError::InvalidRegexExpression)?; From c6e2f9fd9a5283f27ae486d2cc52d01e6b8debfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teemu=20P=C3=A4tsi?= Date: Sat, 26 Apr 2025 18:28:21 +0300 Subject: [PATCH 2/2] expr: Enable ignored test_anchor test --- tests/by-util/test_expr.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/by-util/test_expr.rs b/tests/by-util/test_expr.rs index df2c27c1ce8..b49574f1533 100644 --- a/tests/by-util/test_expr.rs +++ b/tests/by-util/test_expr.rs @@ -618,7 +618,6 @@ mod gnu_expr { .stdout_only("1\n"); } - #[ignore] #[test] fn test_anchor() { new_ucmd!()