Repository navigation
fix(ls): respect line_ending in display_grid when using --zero with column formats - #15505
adamvalves wants to merge 3 commits into
Conversation
…olumn formats When using --zero with -C or -x, lines were terminated by newline instead of NUL because display_grid did not take line_ending into account. Fixes uutils#14774
| LineEnding::Newline => write!(out, "{grid}")?, | ||
| LineEnding::Nul => { | ||
| let grid_str = grid.to_string(); | ||
| let nul_str = grid_str.replace('\n', "\0"); |
There was a problem hiding this comment.
this also replaces newlines inside filenames, e.g. 1\ntest-zero with --zero -C (show-control-chars is on with --zero).
could you please only replace the row terminators?
| for opt in ["-C", "-x"] { | ||
| scene | ||
| .ucmd() | ||
| .args(&["--zero", opt, "-w", "80"]) |
There was a problem hiding this comment.
please also test with a smaller -w to get several rows, so we check every line ends with \0
| .ucmd() | ||
| .args(&["--zero", opt, "-w", "80"]) | ||
| .succeeds() | ||
| .stdout_only("0-test-zero\t2-test-zero\t3-test-zero\x00"); |
There was a problem hiding this comment.
please add the same -C / -x check in the unix block below, with the 1\ntest-zero file
| match line_ending { | ||
| LineEnding::Newline => write!(out, "{grid}")?, | ||
| LineEnding::Nul => { | ||
| struct GridNulWriter<'a, W> { |
There was a problem hiding this comment.
could you please move this struct out of the function? it makes display_grid hard to read
| } | ||
| impl<W: Write> FmtWrite for GridNulWriter<'_, W> { | ||
| fn write_str(&mut self, s: &str) -> std::fmt::Result { | ||
| let res = if s == "\n" { |
There was a problem hiding this comment.
this relies on term_grid writing the row end as a separate "\n" chunk, so a file named just \n would become \0 too, no?
could you please add a test with such a file?
Fixes #14774
Summary of changes
config.line_endingtodisplay_gridinFormat::ColumnsandFormat::Across.LineEnding::Nulis active, format grid rows with\0instead of\n.--zerocombined with-Cand-x.