From 31e414af503cbbc29f40ab6127073be939ffada1 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 7 Jun 2024 14:45:03 -0400 Subject: Fix issue with replacement text printing before its line number --- printmatch.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/printmatch.c b/printmatch.c index ee45a22..a3197f1 100644 --- a/printmatch.c +++ b/printmatch.c @@ -232,6 +232,16 @@ public int fprint_match(FILE *out, const char *file_start, bp_match_t *m, print_ } } + // Bugfix: if pattern matches at the start of a line and first printed character is from + // the replacement string, we need to be sure that the line number gets printed. + // Regression test: `seq 3 | bp '{..$}' -r '#@0'` (should not print "#" before line numbers) + if (r == text) { + if (opts && opts->fprint_between) { + printed += opts->fprint_between(out, m->start, m->start, opts->match_color); + if (opts->replace_color) printed += fprintf(out, "%s", opts->replace_color); + } + } + if (*r == '\\') { ++r; if (*r == 'N') { // \N (nodent) -- cgit v1.2.3