1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

expr: Escape anchor characters within pattern (#7842)

* expr: Escape anchor characters within the core pattern

The anchor characters `^` and `$` are not considered special characters by `expr`
unless they are used as expected on the start or end of the pattern.
This commit is contained in:
Teemu Pätsi 2025-04-28 00:52:35 +03:00 committed by GitHub
parent ddf48facbe
commit 07501be4ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 56 additions and 9 deletions

View file

@ -274,11 +274,10 @@ fn test_length_mb() {
#[test]
fn test_regex() {
// FixME: [2022-12-19; rivy] test disabled as it currently fails due to 'oniguruma' bug (see GH:kkos/oniguruma/issues/279)
// new_ucmd!()
// .args(&["a^b", ":", "a^b"])
// .succeeds()
// .stdout_only("3\n");
new_ucmd!()
.args(&["a^b", ":", "a^b"])
.succeeds()
.stdout_only("3\n");
new_ucmd!()
.args(&["a^b", ":", "a\\^b"])
.succeeds()
@ -288,13 +287,38 @@ fn test_regex() {
.succeeds()
.stdout_only("3\n");
new_ucmd!()
.args(&["-5", ":", "-\\{0,1\\}[0-9]*$"])
.args(&["abc", ":", "^abc"])
.succeeds()
.stdout_only("3\n");
new_ucmd!()
.args(&["^abc", ":", "^^abc"])
.succeeds()
.stdout_only("4\n");
new_ucmd!()
.args(&["b^$ic", ":", "b^\\$ic"])
.succeeds()
.stdout_only("5\n");
new_ucmd!()
.args(&["^^^^^^^^^", ":", "^^^"])
.succeeds()
.stdout_only("2\n");
new_ucmd!()
.args(&["-5", ":", "-\\{0,1\\}[0-9]*$"])
.succeeds()
.stdout_only("2\n");
new_ucmd!().args(&["", ":", ""]).fails().stdout_only("0\n");
new_ucmd!()
.args(&["abc", ":", ""])
.fails()
.stdout_only("0\n");
new_ucmd!()
.args(&["abc", ":", "bc"])
.fails()
.stdout_only("0\n");
new_ucmd!()
.args(&["^abc", ":", "^abc"])
.fails()
.stdout_only("0\n");
}
#[test]
@ -711,7 +735,6 @@ mod gnu_expr {
.stdout_only("\n");
}
#[ignore = "rust-onig bug, see https://github.com/rust-onig/rust-onig/issues/188"]
#[test]
fn test_bre10() {
new_ucmd!()