Skip to content

Commit

Permalink
ls: Fix quoting alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
RenjiSann committed May 15, 2024
1 parent 147c0b6 commit 105024e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2616,12 +2616,24 @@ fn display_grid(
}
} else {
let names = if quoted {
// In case some names are quoted, GNU adds a space before each
// entry that does not start with a quote to make it prettier
// on multiline.
//
// Example:
// ```
// $ ls
// 'a\nb' bar
// foo baz
// ^ ^
// These spaces is added
// ```
names
.map(|n| {
if n.starts_with('\'') {
format!(" {n}")
} else {
if n.starts_with('\'') || n.starts_with('"') {
n
} else {
format!(" {n}")
}
})
.collect()
Expand Down
1 change: 1 addition & 0 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2961,6 +2961,7 @@ fn test_ls_align_unquoted() {
at.touch("'quoted'");

// In TTY
#[cfg(unix)]
scene
.ucmd()
.arg("--color")
Expand Down

0 comments on commit 105024e

Please sign in to comment.