You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adjust record separator when --zero-terminated is specified #530
In common with GNU sed, the record separator should be appropriately adjusted (probably stored in context) for delimiting both input and output records. Currently:
$ printf 'hello\0world\0' | sed -z = | rsed -n l
1\000hello\0002\000world\000$
$ printf 'hello\0world\0' | rust-sed -z = | rsed -n l
1$
hello\000world\000$
I have a working fix for -z. When it's set, sed splits input on NUL, ends output lines with NUL, and the commands that join or split lines (N, G, H, D, P, w and so on) use NUL too. I compared it against GNU sed and 336 of 353 cases match exactly.
The other 17 come from existing bugs that also show up without -z, including #568. One thing it doesn't cover yet is M: under -z, GNU treats NUL as the line break for that regex flag, and doing the same here would mean changing the regex engine, so I'd leave it for a follow-up. The change is about 225 lines across 7 files, mostly in the input/output code, so I wanted to check first: does this approach work for you, and
should I go ahead and open a PR?
Thank you! Please go ahead. For the PR ensure the change is minimal and fits the existing design (see description above), doesn't include any unneeded changes, adds appropriate unit and end-to-end tests.
Activity
sap1110 commentedon Sep 29, 2026
I have a working fix for -z. When it's set, sed splits input on NUL, ends output lines with NUL, and the commands that join or split lines (N, G, H, D, P, w and so on) use NUL too. I compared it against GNU sed and 336 of 353 cases match exactly.
The other 17 come from existing bugs that also show up without -z, including #568. One thing it doesn't cover yet is M: under -z, GNU treats NUL as the line break for that regex flag, and doing the same here would mean changing the regex engine, so I'd leave it for a follow-up. The change is about 225 lines across 7 files, mostly in the input/output code, so I wanted to check first: does this approach work for you, and
should I go ahead and open a PR?
dspinellis commentedon Sep 29, 2026
Thank you! Please go ahead. For the PR ensure the change is minimal and fits the existing design (see description above), doesn't include any unneeded changes, adds appropriate unit and end-to-end tests.
sed: separate lines with NUL when -z is given
sed: separate lines with NUL when -z is given
sed: separate lines with NUL when -z is given
sed: check that --zero-terminated sets null_data in the unit tests