Skip to content

Adjust record separator when --zero-terminated is specified #530

Open

Description

@dspinellis

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$

Activity

  1. sap1110 commented on Sep 29, 2026

    @sap1110
    Contributor

    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?

  2. dspinellis commented on Sep 29, 2026

    @dspinellis
    CollaboratorAuthor

    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.

  3. added a commit that references this issue on Oct 18, 2026
    c47f1f6
  4. added a commit that references this issue on Nov 4, 2026
    2f97098
  5. added a commit that references this issue on Nov 12, 2026
    2d1c7d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions