1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-15 11:36:16 +00:00

Merge pull request #5218 from tertsdiepraam/echo-fix-octal-wrapping

`echo`: fix wrapping behavior of octal sequences
This commit is contained in:
Daniel Hofstetter 2023-10-03 13:52:56 +02:00 committed by GitHub
commit 139f205783
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 126 additions and 57 deletions

View file

@ -236,3 +236,47 @@ fn test_hyphen_values_between() {
.success()
.stdout_is("dumdum dum dum dum -e dum\n");
}
#[test]
fn wrapping_octal() {
// Some odd behavior of GNU. Values of \0400 and greater do not fit in the
// u8 that we write to stdout. So we test that it wraps:
//
// We give it this input:
// \o501 = 1_0100_0001 (yes, **9** bits)
// This should be wrapped into:
// \o101 = 'A' = 0100_0001,
// because we only write a single character
new_ucmd!()
.arg("-e")
.arg("\\0501")
.succeeds()
.stdout_is("A\n");
}
#[test]
fn old_octal_syntax() {
new_ucmd!()
.arg("-e")
.arg("\\1foo")
.succeeds()
.stdout_is("\x01foo\n");
new_ucmd!()
.arg("-e")
.arg("\\43foo")
.succeeds()
.stdout_is("#foo\n");
new_ucmd!()
.arg("-e")
.arg("\\101 foo")
.succeeds()
.stdout_is("A foo\n");
new_ucmd!()
.arg("-e")
.arg("\\1011")
.succeeds()
.stdout_is("A1\n");
}