Repository navigation
Conversation
Inside [...] a / is an ordinary character, so /a[/]b/ matches a/b. Track bracket expressions while scanning a regex literal, with the same rules as gawk's scanner. Fixes uutils#173.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
GNU awk testsuite comparison: |
| // A character class such as `[:alpha:]`. Like gawk, only | ||
| // `[:` nests; `[.` and `[=` do not. | ||
| if rest.get(i + 1) == Some(&b':') | ||
| && let Some(end) = rest[i + 2..].windows(2).position(|w| w == b":]") |
There was a problem hiding this comment.
this search for :] can run past a newline (/[[:x/ then a :] on a later line), so we skip the newline and keep lexing instead of reporting an unterminated regex
could you please stop it at \n? and add a test :)
There was a problem hiding this comment.
Good catch, fixed in 3478c03. The :] search now stops at the first newline, so the newline ends the regex as usual.
The new test regex_class_name_ends_at_newline uses /[[:x/ { print 1 } followed by /:]]/ { print 2 } on the next line. Before the fix, those two lines were lexed as one regex, which then failed with "invalid character class name" (exit 2). Now it is "Unterminated regex" (exit 1), like gawk's "unterminated regexp". (With just /[[:x/ and a :] inside a later string, the bracket never closes, so it was already unterminated before the fix and the test would not have caught it.)
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
…acket # Conflicts: # tests/by-util/test_awk.rs
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
GNU awk testsuite comparison: |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
GNU awk testsuite comparison: |
Fixes #173.
Inside a bracket expression,
/is an ordinary character, so/a[/]b/matchesa/b. The lexer ended the regex at the first/it found, including one inside[...], and then failed to parse the rest of the line.parse_contentnow tracks whether a regex is inside a bracket expression and skips the delimiter there. It follows the same rules as gawk's scanner:]right after[or[^is part of the list, as in[]/]or[^]/].[:alpha:]inside the brackets doesn't close them, so[[:alpha:]/]works.[.and[=don't nest. gawk rejects/a[[=a=]=/]b/and so does this.[\/]and\/still work.String literals are unchanged and still use
memchr3.I compared 15 programs with gawk, covering the cases above, division (
4 / 2,6 / 2 / 3) and unterminated regexes, and all of them match.One existing test changed.
invalid_regex_literal_is_fatalexpected/[q/to reach the regex engine and fail at run time with "unbalanced [". Since the/inside the open[no longer ends the regex,/[q/is now an unterminated regex at parse time with exit status 1, which is what gawk reports ("unterminated regexp", exit 1). I moved those two cases into the new test with that expectation and kept the(cases.The new test
slash_in_regex_bracketfails on main and passes with this change.cargo test --workspacepasses (273 tests), andcargo fmtandcargo clippy --workspace --all-targets -- -D warningsare clean. The issue's suggested test usessub(), which isn't implemented yet, so the test uses~and a bare$0 ~ /[/]/pattern instead.I used Claude Code (Opus 5.5) to help investigate and draft this change; I reproduced the bug and checked the fix myself.