Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/uu/fold/src/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,12 @@ fn process_utf8_chars<W: Write>(line: &str, ctx: &mut FoldContext<'_, W>) -> URe
let mut iter = line.char_indices().peekable();

while let Some((byte_idx, ch)) = iter.next() {
if ch == '\n' {
*ctx.last_space = None;
emit_output(ctx)?;
continue;
}

// Include combining characters with the base character when we are
// measuring by display columns. In character-counting mode every
// scalar value must advance the counter to match `chars().count()`
Expand All @@ -586,12 +592,6 @@ fn process_utf8_chars<W: Write>(line: &str, ctx: &mut FoldContext<'_, W>) -> URe

let next_idx = iter.peek().map_or(line_bytes.len(), |(idx, _)| *idx);

if ch == '\n' {
*ctx.last_space = None;
emit_output(ctx)?;
continue;
}

if *ctx.col_count >= ctx.width {
emit_output(ctx)?;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/by-util/test_fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,18 @@ fn test_zero_width_spaces_in_column_mode() {
.stdout_is(&input);
}

#[test]
fn test_zero_width_after_newline_in_column_mode() {
let input = "abc\n\u{200B}From x\n\u{200D}\u{0301}\nb\n";
for args in [&[][..], &["-s"]] {
new_ucmd!()
.args(args)
.pipe_in(input)
.succeeds()
.stdout_is(input);
}
}

#[test]
fn test_zero_width_spaces_in_character_mode() {
let len = io_buf_size_times_two();
Expand Down
Loading