diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index a3fdef344..ee653d4c4 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -2568,7 +2568,8 @@ fn display_file_name( } } else { // If no coloring is required, we just use target as is. - name.push_str(&target.to_string_lossy()); + // Apply the right quoting + name.push_str(&escape_name(&target.as_os_str(), &config.quoting_style)); } } } diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 3cfba4312..d4692b573 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -2913,3 +2913,43 @@ fn test_ls_multiple_a_A() { .stdout_does_not_contain(".") .stdout_does_not_contain(".."); } + +#[test] +fn test_ls_quoting() { + let scene = TestScenario::new(util_name!()); + + scene + .ccmd("ln") + .arg("-s") + .arg("'need quoting'") + .arg("symlink") + .succeeds(); + scene + .ucmd() + .arg("-l") + .arg("--quoting-style=shell-escape") + .arg("symlink") + .succeeds() + .stdout_contains("\'need quoting\'"); +} + +//#[test] +// Enable when support with color is added +fn test_ls_quoting_auto() { + let scene = TestScenario::new(util_name!()); + + scene + .ccmd("ln") + .arg("-s") + .arg("'need quoting'") + .arg("symlink") + .succeeds(); + scene + .ucmd() + .arg("-l") + .arg("--quoting-style=shell-escape") + .arg("--color=auto") + .arg("symlink") + .succeeds() + .stdout_contains("\'need quoting\'"); +}