From e8c8fd86f3afac874ace49e260a005bcaec6bad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20P=C3=A9ron?= Date: Sun, 19 Nov 2023 02:55:04 +0100 Subject: [PATCH 1/4] ls: set default quoting style to literal if output is not TTY --- src/uu/ls/src/ls.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 88af56bb186..a37157df8b7 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -622,6 +622,10 @@ fn extract_quoting_style(options: &clap::ArgMatches, show_control: bool) -> Quot } } else if options.get_flag(options::DIRED) { QuotingStyle::Literal { show_control } + } else if !std::io::stdout().is_terminal() { + // By default, `ls` uses Literal quoting when + // outputing to a non-terminal file descriptor + QuotingStyle::Literal { show_control } } else { // TODO: use environment variable if available QuotingStyle::Shell { From 4283c9f6f4db5a5bcce8f835f3a7f27febc4e9f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20P=C3=A9ron?= Date: Sun, 19 Nov 2023 03:45:34 +0100 Subject: [PATCH 2/4] tests/ls: Fix quoting tests that now run with Literal as default --- tests/by-util/test_ls.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 07ea8c9cd63..b323518e128 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -2453,13 +2453,16 @@ fn test_ls_quoting_style() { { at.touch("one\ntwo"); at.touch("one\\two"); - // Default is shell-escape + // Default is literal, when stdout is not a TTY. + // Otherwise, it is shell-escape scene .ucmd() .arg("--hide-control-chars") .arg("one\ntwo") .succeeds() - .stdout_only("'one'$'\\n''two'\n"); + .stdout_only("one?two\n"); + // TODO: TTY-expected output, find a way to check this as well + // .stdout_only("'one'$'\\n''two'\n"); for (arg, correct) in [ ("--quoting-style=literal", "one?two"), @@ -2546,7 +2549,9 @@ fn test_ls_quoting_style() { .ucmd() .arg("one two") .succeeds() - .stdout_only("'one two'\n"); + .stdout_only("one two\n"); + // TODO: TTY-expected output + // .stdout_only("'one two'\n"); for (arg, correct) in [ ("--quoting-style=literal", "one two"), @@ -2609,7 +2614,9 @@ fn test_ls_quoting_and_color() { .arg("--color") .arg("one two") .succeeds() - .stdout_only("'one two'\n"); + .stdout_only("one two\n"); + // TODO: TTY-expected output + // .stdout_only("'one two'\n"); } #[test] From 02724fb2fea175a3d59f0cf50f3d7e7e33aea272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20P=C3=A9ron?= Date: Sun, 19 Nov 2023 12:41:10 +0100 Subject: [PATCH 3/4] ls: Fix formatting/linting/spelling issues --- src/uu/ls/src/ls.rs | 6 ++---- tests/by-util/test_ls.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index a37157df8b7..6bd62b8389f 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -620,11 +620,9 @@ fn extract_quoting_style(options: &clap::ArgMatches, show_control: bool) -> Quot QuotingStyle::C { quotes: quoting_style::Quotes::Double, } - } else if options.get_flag(options::DIRED) { - QuotingStyle::Literal { show_control } - } else if !std::io::stdout().is_terminal() { + } else if options.get_flag(options::DIRED) || !std::io::stdout().is_terminal() { // By default, `ls` uses Literal quoting when - // outputing to a non-terminal file descriptor + // writing to a non-terminal file descriptor QuotingStyle::Literal { show_control } } else { // TODO: use environment variable if available diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index b323518e128..cc8af38442b 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -2461,8 +2461,8 @@ fn test_ls_quoting_style() { .arg("one\ntwo") .succeeds() .stdout_only("one?two\n"); - // TODO: TTY-expected output, find a way to check this as well - // .stdout_only("'one'$'\\n''two'\n"); + // TODO: TTY-expected output, find a way to check this as well + // .stdout_only("'one'$'\\n''two'\n"); for (arg, correct) in [ ("--quoting-style=literal", "one?two"), @@ -2550,8 +2550,8 @@ fn test_ls_quoting_style() { .arg("one two") .succeeds() .stdout_only("one two\n"); - // TODO: TTY-expected output - // .stdout_only("'one two'\n"); + // TODO: TTY-expected output + // .stdout_only("'one two'\n"); for (arg, correct) in [ ("--quoting-style=literal", "one two"), @@ -2615,8 +2615,8 @@ fn test_ls_quoting_and_color() { .arg("one two") .succeeds() .stdout_only("one two\n"); - // TODO: TTY-expected output - // .stdout_only("'one two'\n"); + // TODO: TTY-expected output + // .stdout_only("'one two'\n"); } #[test] From 6169437155327ee6c6dbbc176c4adc16c2600f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20P=C3=A9ron?= Date: Tue, 5 Dec 2023 10:40:42 +0100 Subject: [PATCH 4/4] tests/ls: Fix windows escaped tests --- tests/by-util/test_ls.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index cc8af38442b..43f3f660044 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -3148,11 +3148,8 @@ fn test_ls_path() { .stdout_is(expected_stdout); let abs_path = format!("{}/{}", at.as_string(), path); - let expected_stdout = if cfg!(windows) { - format!("\'{abs_path}\'\n") - } else { - format!("{abs_path}\n") - }; + let expected_stdout = format!("{abs_path}\n"); + scene.ucmd().arg(&abs_path).run().stdout_is(expected_stdout); let expected_stdout = format!("{path}\n{file1}\n");