Skip to content

Commit fd8fcda

Browse files
Fix edge case
1 parent f1aab0f commit fd8fcda

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

text/grep.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl Patterns {
359359

360360
let mut any_pattern_matched = false;
361361

362-
'next_pattern: for p in patterns {
362+
for p in patterns {
363363
let mut current_string_index = 0_usize;
364364

365365
loop {
@@ -390,7 +390,7 @@ impl Patterns {
390390
if regexec_return_value != 0 {
391391
debug_assert!(regexec_return_value == REG_NOMATCH);
392392

393-
continue 'next_pattern;
393+
break;
394394
}
395395

396396
if !collect_matching_substrings {
@@ -404,12 +404,17 @@ impl Patterns {
404404
let start = usize::try_from(regmatch_t.rm_so).unwrap();
405405
let end = usize::try_from(regmatch_t.rm_eo).unwrap();
406406

407-
debug_assert!(end > 0_usize);
407+
// TODO
408+
// Is this the right fix?
409+
// The edge case is:
410+
//
411+
// grep -o ''
412+
if end == 0_usize {
413+
break;
414+
}
408415

409416
matching_substrings.push(current_string_slice[start..end].to_vec());
410417

411-
debug_assert!(end > current_string_index);
412-
413418
current_string_index += end;
414419
}
415420
}

text/tests/grep/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,4 +1425,6 @@ KEYWORD
14251425
"",
14261426
0_i32,
14271427
);
1428+
1429+
grep_test(&["-o", ""], INPUT, "", "", 0_i32);
14281430
}

0 commit comments

Comments
 (0)