Skip to content

sed: keep only the low byte of a \d or \o escape above 255 - #641

Open
qodelicious wants to merge 1 commit into
uutils:mainfrom
qodelicious:numeric-escape-wrap
Open

qodelicious wants to merge 1 commit into
uutils:mainfrom
qodelicious:numeric-escape-wrap

Conversation

@qodelicious

Copy link
Copy Markdown
Contributor

GNU sed keeps only the low byte of a \d or \o value, so \d513 and \o401 are both 0x01 and \d321 is A. We turned the whole number into a char, so they came out as U+0201 and U+0101 (two bytes each in a UTF-8 locale).

$ echo a | ./target/debug/sed 's/./\d513/' | od -c
0000000 310 201  \n
$ echo a | /usr/bin/sed 's/./\d513/' | od -c    # GNU sed 4.9
0000000 001  \n

This is one of the cases in the GNU testsuite's convert-number.sh. parse_numeric_escape now masks the value to 8 bits for the byte escapes (\d, \o, \x). \u and \U are untouched. Since the regex, replacement and y strings all go through parse_char_escape, they all get it.

Added test_numeric_escape_keeps_the_low_byte and two unit tests in delimited_parser.rs. They fail on main and pass with the change, and the output matches GNU sed 4.9. cargo test, cargo fmt --check and cargo clippy --all-targets --all-features -- -D warnings pass.

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.08%. Comparing base (786c87f) to head (a9a71df).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #641   +/-   ##
=======================================
  Coverage   95.07%   95.08%           
=======================================
  Files          14       14           
  Lines        7436     7451   +15     
  Branches      439      440    +1     
=======================================
+ Hits         7070     7085   +15     
  Misses        365      365           
  Partials        1        1           
Flag Coverage Δ
macos_latest 96.58% <100.00%> (+<0.01%) ⬆️
ubuntu_latest 96.52% <100.00%> (+<0.01%) ⬆️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant