1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

ls: Fix --{show, hide}-control-chars logic

This commit is contained in:
Jan Verbeek 2021-08-31 12:55:17 +02:00
parent a93959aa44
commit 4d6faae555
2 changed files with 9 additions and 20 deletions

View file

@ -428,11 +428,10 @@ impl Config {
#[allow(clippy::needless_bool)]
let show_control = if options.is_present(options::HIDE_CONTROL_CHARS) {
false
} else if options.is_present(options::SHOW_CONTROL_CHARS) || atty::is(atty::Stream::Stdout)
{
} else if options.is_present(options::SHOW_CONTROL_CHARS) {
true
} else {
false
!atty::is(atty::Stream::Stdout)
};
let quoting_style = if let Some(style) = options.value_of(options::QUOTING_STYLE) {

View file

@ -1416,6 +1416,7 @@ fn test_ls_quoting_style() {
// Default is shell-escape
scene
.ucmd()
.arg("--hide-control-chars")
.arg("one\ntwo")
.succeeds()
.stdout_only("'one'$'\\n''two'\n");
@ -1437,23 +1438,8 @@ fn test_ls_quoting_style() {
] {
scene
.ucmd()
.arg(arg)
.arg("one\ntwo")
.succeeds()
.stdout_only(format!("{}\n", correct));
}
for (arg, correct) in &[
("--quoting-style=literal", "one?two"),
("-N", "one?two"),
("--literal", "one?two"),
("--quoting-style=shell", "one?two"),
("--quoting-style=shell-always", "'one?two'"),
] {
scene
.ucmd()
.arg(arg)
.arg("--hide-control-chars")
.arg(arg)
.arg("one\ntwo")
.succeeds()
.stdout_only(format!("{}\n", correct));
@ -1463,7 +1449,7 @@ fn test_ls_quoting_style() {
("--quoting-style=literal", "one\ntwo"),
("-N", "one\ntwo"),
("--literal", "one\ntwo"),
("--quoting-style=shell", "one\ntwo"),
("--quoting-style=shell", "one\ntwo"), // FIXME: GNU ls quotes this case
("--quoting-style=shell-always", "'one\ntwo'"),
] {
scene
@ -1490,6 +1476,7 @@ fn test_ls_quoting_style() {
] {
scene
.ucmd()
.arg("--hide-control-chars")
.arg(arg)
.arg("one\\two")
.succeeds()
@ -1505,6 +1492,7 @@ fn test_ls_quoting_style() {
] {
scene
.ucmd()
.arg("--hide-control-chars")
.arg(arg)
.arg("one\n&two")
.succeeds()
@ -1535,6 +1523,7 @@ fn test_ls_quoting_style() {
] {
scene
.ucmd()
.arg("--hide-control-chars")
.arg(arg)
.arg("one two")
.succeeds()
@ -1558,6 +1547,7 @@ fn test_ls_quoting_style() {
] {
scene
.ucmd()
.arg("--hide-control-chars")
.arg(arg)
.arg("one")
.succeeds()