Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 14 additions & 1 deletion src/uu/ptx/src/ptx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,20 @@ fn create_word_set(config: &Config, filter: &WordFilter, file_map: &FileMap) ->
};
// match words with given regex
for mat in reg.find_iter(line) {
let (beg, end) = (mat.start(), mat.end());
let (mut beg, end) = (mat.start(), mat.end());

// GNU-compatible default behavior:
// with default regexp, keyword must start at first alphabetic char.
if filter.word_regex == Config::default().context_regex {
let matched = &line[beg..end];
if let Some((off, _)) = matched.char_indices().find(|(_, c)| c.is_alphabetic())
Comment thread
Xylphy marked this conversation as resolved.
Outdated
{
beg += off;
} else {
continue;
}
}

if config.input_ref && ((beg, end) == (ref_beg, ref_end)) {
continue;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/by-util/test_ptx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ fn test_gnu_mode_dumb_format() {
new_ucmd!().pipe_in("a b").succeeds().stdout_only(
" a b\n a b\n",
);

new_ucmd!()
.pipe_in("2a")
.succeeds()
.stdout_only(format!("{}2 a\n", " ".repeat(35)));
}

#[test]
Expand Down Expand Up @@ -330,6 +335,15 @@ fn test_unicode_padding_alignment() {
.stdout_only(" a\n é\n");
}

#[test]
fn test_gnu_compat_numeric_token_with_emoji_produces_no_index() {
// GNU ptx produces no output for this input in default mode.
new_ucmd!()
.pipe_in("012345678901234567890123456789🛠\n")
.succeeds()
.no_output();
}

#[test]
fn test_unicode_truncation_alignment() {
new_ucmd!()
Expand Down
Loading