Applied, thank you

On Tue, Dec 21, 2021 at 2:01 PM Dominique Martinet
<asmad...@codewreck.org> wrote:
>
> It is perfectly valid to start a regex with ^ and have other patterns
> with \| that can match more than once, e.g. the following example
> should print ca, as illustrated with gnu sed:
> $ echo 'abca' | sed -e 's/^a\|b//g'
> ca
>
> busybox before patch:
> $ echo 'abca' | busybox sed -e 's/^a\|b//g'
> bca
>
> busybox after patch:
> $ echo 'abca' | ./busybox sed -e 's/^a\|b//g'
> ca
>
> regcomp handles ^ perfectly well as illustrated with the second 'a' that
> did not match in the example, we ca leave the non-repeating to it if
> appropriate.
> The check had been added before using regcomp and was required at the
> time (f36635cec6da) but no longer makes sense now.
>
> (tested with glibc and musl libc)
>
> Signed-off-by: Dominique Martinet <asmad...@codewreck.org>
> ---
>
> stumbled on this because one of my script stripping first/last char in a
> single 's/^x\|x$//g' didn't work on alpine with busybox sed.
>
> Thanks!
>
>
>  editors/sed.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/editors/sed.c b/editors/sed.c
> index a6845a979668..e8c82ac63ac4 100644
> --- a/editors/sed.c
> +++ b/editors/sed.c
> @@ -435,8 +435,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char 
> *substr)
>                 switch (substr[idx]) {
>                 /* Replace all occurrences */
>                 case 'g':
> -                       if (match[0] != '^')
> -                               sed_cmd->which_match = 0;
> +                       sed_cmd->which_match = 0;
>                         break;
>                 /* Print pattern space */
>                 case 'p':
> --
> 2.31.1
>
> _______________________________________________
> busybox mailing list
> busybox@busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to