Skip to content

expr: '$' should act as a special character only at the end of regex or subexpression #7951

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

Open
frendsick opened this issue May 18, 2025 · 2 comments · May be fixed by #7953
Open

expr: '$' should act as a special character only at the end of regex or subexpression #7951

frendsick opened this issue May 18, 2025 · 2 comments · May be fixed by #7953
Labels

Comments

@frendsick
Copy link
Contributor

frendsick commented May 18, 2025

The '$' character should be escaped when it is not used in a spot that makes it act as a special character.

It is the same as ^, but refers to end of pattern space. $ also acts as a special character only at the end of the regular expression or subexpression (that is, before \) or \|), and its use at the end of a subexpression is not portable.

Reference: https://www.gnu.org/software/sed/manual/html_node/BRE-syntax.html

The test test_bre11 is failing because the '$' is not escaped. On the other hand, test_bre13 works almost by accident, because the '$' character is never escaped in the first place. Both of these tests should pass after fixing the interpretation of the '$' character.

@sylvestre
Copy link
Contributor

could you please provide a simple test case demonstrating this issue ? thanks

@frendsick frendsick linked a pull request May 18, 2025 that will close this issue
@frendsick
Copy link
Contributor Author

I created a PR #7953 that should fix this.

The test_bre11 is a simple test case for a situation where the '$' should be handled literally. The PR un-ignores it.

The test_bre13 is a test case where the '$' should be handled as an end-of-pattern anchor because it is at the end of a capturing group, so it is before \).

Even simpler test case than test_bre13 where the '$' should be handled as its special meaning would be the following (also included by #7953):

    new_ucmd!()
        .args(&["ab", ":", "a\\(b$\\)"])
        .succeeds()
        .stdout_only("b\n");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants