Skip to content

--posix should reject GNU substitute flags i/I #401

@sylvestre

Description

@sylvestre

Bug

--posix does not actually reject the GNU i / I substitute flag.
The flag is silently accepted, which violates POSIX strictness when
the user opts into it.

Reproduction

$ echo a | /usr/bin/sed --posix 's/a/b/i'
sed: -e expression #1, char 7: unknown option to 's'

$ echo a | ./target/release/sed --posix 's/a/b/i'
b                # silently honored, should be an error

What it should do

When --posix is set, all of the GNU substitute-flag extensions
(i, I, m, M, e) must be rejected with the same
"unknown option to 's'" wording style we already use for unknown flags.

--posix is already plumbed elsewhere (e.g. compiler.rs:1289 uses it
to choose the address-count of =), so the value is available.

Suspected place to add it

src/sed/compiler.rs:854compile_subst_flags. The function
already reaches a format!("invalid substitute flag: '{other}'")
branch around line 938. The fix is in the existing 'i' | 'I' =>
arm: when posix == true, fall through to the same error path.

'i' | 'I' => {
    if posix {
        return compilation_error("unknown option to 's'" );
    }
    subst.ignore_case = true;
    line.advance();
}

Same treatment for m/M/e once those land (issues #9, #15).

Affected GNU testsuite tests

posix-mode-s (the for opt in i I m M ; loop at the top of the
script).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions