mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
expr: Fix parsing negated character classes "[^a]" (#7884)
* expr: Fix regex escape logic We have to track if the previous character was already escaped to determine if the '\' character should be interpreted as an escape character. * expr: Fix parsing caret (^) as character class negation token * expr: Add tests for parsing carets in regex * expr: Add missing semicolon * expr: Simplify boolean assignment Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> --------- Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
parent
69d5cf40b1
commit
4ee53acad0
2 changed files with 32 additions and 2 deletions
|
@ -302,6 +302,26 @@ fn test_regex() {
|
|||
.args(&["^^^^^^^^^", ":", "^^^"])
|
||||
.succeeds()
|
||||
.stdout_only("2\n");
|
||||
new_ucmd!()
|
||||
.args(&["ab[^c]", ":", "ab[^c]"])
|
||||
.succeeds()
|
||||
.stdout_only("3\n"); // Matches "ab["
|
||||
new_ucmd!()
|
||||
.args(&["ab[^c]", ":", "ab\\[^c]"])
|
||||
.succeeds()
|
||||
.stdout_only("6\n");
|
||||
new_ucmd!()
|
||||
.args(&["[^a]", ":", "\\[^a]"])
|
||||
.succeeds()
|
||||
.stdout_only("4\n");
|
||||
new_ucmd!()
|
||||
.args(&["\\a", ":", "\\\\[^^]"])
|
||||
.succeeds()
|
||||
.stdout_only("2\n");
|
||||
new_ucmd!()
|
||||
.args(&["^a", ":", "^^[^^]"])
|
||||
.succeeds()
|
||||
.stdout_only("2\n");
|
||||
new_ucmd!()
|
||||
.args(&["-5", ":", "-\\{0,1\\}[0-9]*$"])
|
||||
.succeeds()
|
||||
|
@ -319,6 +339,10 @@ fn test_regex() {
|
|||
.args(&["^abc", ":", "^abc"])
|
||||
.fails()
|
||||
.stdout_only("0\n");
|
||||
new_ucmd!()
|
||||
.args(&["abc", ":", "ab[^c]"])
|
||||
.fails()
|
||||
.stdout_only("0\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue