Skip to content

Commit

Permalink
Fix handling escaped delimiter for ex_range function (#113)
Browse files Browse the repository at this point in the history
Function search_init removes escape character if it escapes a
delimiter, but it should consider when an backslash character is
not an escape character (this occurs when two backslash). In latter
case the escape character should be included in re string.

This patch can be tested with the following commands.

    $ printf '%s\n' '\' > test.txt
    $ printf '%s\n' '/\\/' 'q' | ex test.txt

Before this patch the previous command gives 'Pattern not found',
because the last two caracters of the command becomes the single
delimiter in the regular expression, i.e. it didn't recognize the
delimiter.

Co-authored-by: Bosco G. G <jbgg@disroot.org>
  • Loading branch information
jbgg and jbgg committed Dec 13, 2022
1 parent 4689fbd commit e705426
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions common/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,14 @@ prev: if (sp->re == NULL) {
++p;
break;
}
if (plen > 1 && p[0] == '\\' && p[1] == delim) {
++p;
--plen;
if (plen > 1 && p[0] == '\\') {
if (p[1] == delim) {
++p;
--plen;
} else if ( p[1] == '\\') {
*t++ = *p++;
--plen;
}
}
}
if (epp != NULL)
Expand Down

0 comments on commit e705426

Please sign in to comment.