mirror of
https://github.com/uutils/coreutils
synced 2025-01-19 00:24:13 +00:00
echo: add support for \NNN octal escape sequence
This commit is contained in:
parent
4623575a66
commit
1ad10dd371
2 changed files with 37 additions and 0 deletions
|
@ -54,6 +54,16 @@ fn print_escaped(input: &str, mut output: impl Write) -> io::Result<bool> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is for the \NNN syntax for octal sequences.
|
||||||
|
// Note that '0' is intentionally omitted because that
|
||||||
|
// would be the \0NNN syntax.
|
||||||
|
if let Some('1'..='8') = iter.peek() {
|
||||||
|
if let Some(parsed) = parse_code(&mut iter, 8, 3) {
|
||||||
|
write!(output, "{parsed}")?;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(next) = iter.next() {
|
if let Some(next) = iter.next() {
|
||||||
let unescaped = match next {
|
let unescaped = match next {
|
||||||
'\\' => '\\',
|
'\\' => '\\',
|
||||||
|
|
|
@ -253,3 +253,30 @@ fn wrapping_octal() {
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_is("A\n");
|
.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("\\101foo")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is("Afoo\n");
|
||||||
|
|
||||||
|
new_ucmd!()
|
||||||
|
.arg("-e")
|
||||||
|
.arg("\\1011")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is("A1\n");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue