Skip to content

Commit b5a60a9

Browse files
JaneIllariosgmarz
authored andcommitted
Unexpand: use byte count for multibyte characters for column width when using -a flag (uutils#9949)
* Remove Unicode width calculation for characters * Add test for unexpand with multibyte UTF-8 input
1 parent d08481a commit b5a60a9

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/uu/unexpand/src/unexpand.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::num::IntErrorKind;
1313
use std::path::Path;
1414
use std::str::from_utf8;
1515
use thiserror::Error;
16-
use unicode_width::UnicodeWidthChar;
1716
use uucore::display::Quotable;
1817
use uucore::error::{FromIo, UError, UResult, USimpleError};
1918
use uucore::translate;
@@ -279,11 +278,7 @@ fn next_char_info(uflag: bool, buf: &[u8], byte: usize) -> (CharType, usize, usi
279278
Some(' ') => (CharType::Space, 0, 1),
280279
Some('\t') => (CharType::Tab, 0, 1),
281280
Some('\x08') => (CharType::Backspace, 0, 1),
282-
Some(c) => (
283-
CharType::Other,
284-
UnicodeWidthChar::width(c).unwrap_or(0),
285-
nbytes,
286-
),
281+
Some(_) => (CharType::Other, nbytes, nbytes),
287282
None => {
288283
// invalid char snuck past the utf8_validation_iterator somehow???
289284
(CharType::Other, 1, 1)

tests/by-util/test_unexpand.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,15 @@ fn test_non_utf8_filename() {
295295

296296
ucmd.arg(&filename).succeeds().stdout_is("\ta\n");
297297
}
298+
299+
#[test]
300+
fn unexpand_multibyte_utf8_gnu_compat() {
301+
// Verifies GNU-compatible behavior: column position uses byte count, not display width
302+
// "1ΔΔΔ5" is 8 bytes (1 + 2*3 + 1), already at tab stop 8
303+
// So 3 spaces should NOT convert to tab (would need 8 more to reach tab stop 16)
304+
new_ucmd!()
305+
.args(&["-a"])
306+
.pipe_in("1ΔΔΔ5 99999\n")
307+
.succeeds()
308+
.stdout_is("1ΔΔΔ5 99999\n");
309+
}

0 commit comments

Comments
 (0)