Skip to content
Merged
11 changes: 11 additions & 0 deletions src/sed/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const DEFAULT_OUTPUT_WIDTH: usize = 60;
const ERR_ADDRESS_0_USAGE: &str =
"address 0 can only be used with ~step, a second regular expression, or a read command";

const ERR_UNKNOWN_OPTION_TO_S: &str = "unknown option to 's'";

// Handling required after processing a command
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum CommandHandling {
Expand Down Expand Up @@ -918,10 +920,19 @@ pub fn compile_subst_flags(
}

'i' | 'I' => {
if posix {
return compilation_error(lines, line, ERR_UNKNOWN_OPTION_TO_S);
}
subst.ignore_case = true;
line.advance();
}

'm' | 'M' => {
if posix {
return compilation_error(lines, line, ERR_UNKNOWN_OPTION_TO_S);
}
}

'e' => {
if posix || sandbox {
return compilation_error(
Expand Down
16 changes: 16 additions & 0 deletions tests/by-util/test_sed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1604,3 +1604,19 @@ fn test_print_first_line_no_newline() {
.succeeds()
.stdout_is("foo");
}

//--posix should reject GNU substitute flags i/I https://github.com/uutils/sed/issues/401
#[test]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a test for the m flag (different code path).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done :)

fn test_posix_reject_flags() {
new_ucmd!()
.args(&["--posix", "s/a/b/i"])
.fails()
.code_is(1)
.stderr_is("sed: <script argument 1>:1:7: error: unknown option to 's'\n");

new_ucmd!()
.args(&["--posix", "s/a/b/m"])
.fails()
.code_is(1)
.stderr_is("sed: <script argument 1>:1:7: error: unknown option to 's'\n");
}
Loading