Skip to content

Commit 01ac6df

Browse files
Merge pull request #8135 from willshuttleworth/stty-set-undefined
stty: fix mappings with empty string literal args
1 parent 6023888 commit 01ac6df

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/uu/stty/src/stty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ fn apply_char_mapping(termios: &mut Termios, mapping: &(SpecialCharacterIndices,
598598
//
599599
// This function returns the ascii value of valid control chars, or ControlCharMappingError if invalid
600600
fn string_to_control_char(s: &str) -> Result<u8, ControlCharMappingError> {
601-
if s == "undef" || s == "^-" {
601+
if s == "undef" || s == "^-" || s.is_empty() {
602602
return Ok(0);
603603
}
604604

tests/by-util/test_stty.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ fn runs() {
2222
#[test]
2323
#[ignore = "Fails because cargo test does not run in a tty"]
2424
fn print_all() {
25-
let res = new_ucmd!().succeeds();
25+
let res = new_ucmd!().args(&["--all"]).succeeds();
2626

2727
// Random selection of flags to check for
2828
for flag in [
29-
"parenb", "parmrk", "ixany", "iuclc", "onlcr", "ofdel", "icanon", "noflsh",
29+
"parenb", "parmrk", "ixany", "onlcr", "ofdel", "icanon", "noflsh",
3030
] {
3131
res.stdout_contains(flag);
3232
}
@@ -167,3 +167,37 @@ fn invalid_baud_setting() {
167167
.fails()
168168
.stderr_contains("invalid ospeed '995'");
169169
}
170+
171+
#[test]
172+
#[ignore = "Fails because cargo test does not run in a tty"]
173+
fn set_mapping() {
174+
new_ucmd!().args(&["intr", "'"]).succeeds();
175+
new_ucmd!()
176+
.args(&["--all"])
177+
.succeeds()
178+
.stdout_contains("intr = '");
179+
180+
new_ucmd!().args(&["intr", "undef"]).succeeds();
181+
new_ucmd!()
182+
.args(&["--all"])
183+
.succeeds()
184+
.stdout_contains("intr = <undef>");
185+
186+
new_ucmd!().args(&["intr", "^-"]).succeeds();
187+
new_ucmd!()
188+
.args(&["--all"])
189+
.succeeds()
190+
.stdout_contains("intr = <undef>");
191+
192+
new_ucmd!().args(&["intr", ""]).succeeds();
193+
new_ucmd!()
194+
.args(&["--all"])
195+
.succeeds()
196+
.stdout_contains("intr = <undef>");
197+
198+
new_ucmd!().args(&["intr", "^C"]).succeeds();
199+
new_ucmd!()
200+
.args(&["--all"])
201+
.succeeds()
202+
.stdout_contains("intr = ^C");
203+
}

0 commit comments

Comments
 (0)