-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
expr: Escape anchor characters within pattern #7842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expr: Escape anchor characters within pattern #7842
Conversation
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.
It is not escaped by GNU `expr` either
GNU testsuite comparison:
|
The `rust-onig` bug still exists but parsing carets is fixed within uutils' `expr`
GNU testsuite comparison:
|
GNU testsuite comparison:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves the character escaping logic in regexp pattern definitions and reactivates/upgrades tests to verify the new behavior.
- Core pattern extraction now removes any extra leading '^' and escapes internal '^' characters.
- Tests have been updated to cover various scenarios including patterns starting with '^', '*' and multiple '^' occurrences.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
tests/by-util/test_expr.rs | Updated tests to reflect the new escaping behavior for patterns. |
src/uu/expr/src/syntax_tree.rs | Reworked regex string building logic to correctly escape internal '^' characters. |
Comments suppressed due to low confidence (2)
src/uu/expr/src/syntax_tree.rs:170
- [nitpick] Consider renaming the variable 'prev' to a more descriptive name like 'previous_char' to improve code clarity.
let mut prev = first.unwrap_or_default();
tests/by-util/test_expr.rs:293
- [nitpick] Consider adding an inline comment that explains the expected output for patterns starting with '^' to clarify the transformation rules for future maintainers.
new_ucmd!().args(&["^abc", ":", "^^abc"])
and it passes: |
Escape the regexp start of string anchor characters '^' within pattern definitions. Only keep the start anchor as is if it is at the beginning of the user input pattern.
Changes
Testing
fixes #7663