1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Merge pull request #8135 from willshuttleworth/stty-set-undefined

stty: fix mappings with empty string literal args
This commit is contained in:
Will Shuttleworth 2025-06-16 03:45:11 -04:00 committed by GitHub
parent 6023888363
commit 01ac6dfd18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 3 deletions

View file

@ -598,7 +598,7 @@ fn apply_char_mapping(termios: &mut Termios, mapping: &(SpecialCharacterIndices,
// //
// This function returns the ascii value of valid control chars, or ControlCharMappingError if invalid // This function returns the ascii value of valid control chars, or ControlCharMappingError if invalid
fn string_to_control_char(s: &str) -> Result<u8, ControlCharMappingError> { fn string_to_control_char(s: &str) -> Result<u8, ControlCharMappingError> {
if s == "undef" || s == "^-" { if s == "undef" || s == "^-" || s.is_empty() {
return Ok(0); return Ok(0);
} }

View file

@ -22,11 +22,11 @@ fn runs() {
#[test] #[test]
#[ignore = "Fails because cargo test does not run in a tty"] #[ignore = "Fails because cargo test does not run in a tty"]
fn print_all() { fn print_all() {
let res = new_ucmd!().succeeds(); let res = new_ucmd!().args(&["--all"]).succeeds();
// Random selection of flags to check for // Random selection of flags to check for
for flag in [ for flag in [
"parenb", "parmrk", "ixany", "iuclc", "onlcr", "ofdel", "icanon", "noflsh", "parenb", "parmrk", "ixany", "onlcr", "ofdel", "icanon", "noflsh",
] { ] {
res.stdout_contains(flag); res.stdout_contains(flag);
} }
@ -167,3 +167,37 @@ fn invalid_baud_setting() {
.fails() .fails()
.stderr_contains("invalid ospeed '995'"); .stderr_contains("invalid ospeed '995'");
} }
#[test]
#[ignore = "Fails because cargo test does not run in a tty"]
fn set_mapping() {
new_ucmd!().args(&["intr", "'"]).succeeds();
new_ucmd!()
.args(&["--all"])
.succeeds()
.stdout_contains("intr = '");
new_ucmd!().args(&["intr", "undef"]).succeeds();
new_ucmd!()
.args(&["--all"])
.succeeds()
.stdout_contains("intr = <undef>");
new_ucmd!().args(&["intr", "^-"]).succeeds();
new_ucmd!()
.args(&["--all"])
.succeeds()
.stdout_contains("intr = <undef>");
new_ucmd!().args(&["intr", ""]).succeeds();
new_ucmd!()
.args(&["--all"])
.succeeds()
.stdout_contains("intr = <undef>");
new_ucmd!().args(&["intr", "^C"]).succeeds();
new_ucmd!()
.args(&["--all"])
.succeeds()
.stdout_contains("intr = ^C");
}