Skip to content

emits a spurious -- context separator between adjacent groups #24

Closed

Description

@sylvestre

With before-context (-B/-C), uu_grep prints a -- group separator between two output groups even when they are adjacent — i.e. the next group's context begins on the line immediately after the last line already printed. GNU only prints -- when there is a real gap (one or more skipped lines) between groups.

Found by the differential fuzzer (fuzz_grep).

Input is five lines: a, b, empty, empty, c. Pattern . matches the three non-empty lines.

Rust (incorrect)

$ printf 'a\nb\n\n\nc\n' | ./target/release/grep -e '.' -B 2
a
b
--


c
# Exit code: 0

GNU (correct)

$ printf 'a\nb\n\n\nc\n' | LC_ALL=C /usr/bin/grep -e '.' -B 2
a
b


c
# Exit code: 0

The first group ends at line 2 (b). The match on line 5 (c) pulls in before-context lines 3 and 4, so the second group starts at line 3 — immediately after line 2. The groups touch, so no separator belongs there: GNU merges them, uu_grep inserts --.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions