Skip to content

sed - script parser skips CR, VT, FF (and 0x85, 0xA0) as blanks; GNU skips only space and tab #654

Open

Description

@sylvestre

Wherever the script parser skips blanks (between address and command, after a command, before
one-line a/i/c text, before a w/r file name, ...), GNU sed skips only space and tab.
uutils sed skips every Unicode whitespace character, including carriage return, vertical tab,
form feed and the raw bytes 0x85 and 0xA0. As a result:

  • a script saved with CRLF line endings runs here, where GNU stops with
    extra characters after command;
  • a leading \v, \f or \r is silently dropped from one-line a/i/c text and from
    file names.

Reproduction

Rust (incorrect)

$ printf 'a\n' | ./target/release/sed $'p\r'
a
a
# Exit code: 0

$ printf 'a\n' | ./target/release/sed $'1a\vfoo' | od -An -c
   a  \n   f   o   o  \n
# Exit code: 0

GNU (correct)

$ printf 'a\n' | /usr/bin/sed $'p\r'
/usr/bin/sed: -e expression #1, char 2: extra characters after command
# Exit code: 1

$ printf 'a\n' | /usr/bin/sed $'1a\vfoo' | od -An -c
   a  \n  \v   f   o   o  \n
# Exit code: 0

Root cause

ScriptCharProvider::eat_spaces in src/sed/script_char_provider.rs:64-69:

/// Advances the position past any whitespace characters.
pub fn eat_spaces(&mut self) {
    while self.pos < self.line.len() && self.current().is_whitespace() {
        self.advance();
    }
}

current() maps each byte to a char, so char::is_whitespace is also true for the bytes
0x85 and 0xA0 (U+0085, U+00A0).

Test

#[test]
fn test_carriage_return_after_command_rejected() {
    new_ucmd!()
        .arg("p\r")
        .pipe_in("a\n")
        .fails()
        .code_is(1);
}

#[test]
fn test_vertical_tab_kept_in_one_line_text() {
    new_ucmd!()
        .arg("1a\x0bfoo")
        .pipe_in("a\n")
        .succeeds()
        .stdout_is("a\n\x0bfoo\n");
}

Reported by Anthropic's OSS Scanner (ANT-2026-Q3PRSLF7).

Activity

  1. added
    bug
    good first issue
    oss-scanner
    gnu-compat
    on Nov 9, 2026
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

    buggnu-compatgood first issueoss-scanner

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions