regex: treat \+, \? as repetitions in BRE
authorSzabolcs Nagy <nsz@port70.net>
Sat, 18 Apr 2015 17:28:49 +0000 (17:28 +0000)
committerRich Felker <dalias@aerifal.cx>
Sun, 31 Jan 2016 01:53:42 +0000 (20:53 -0500)
These are undefined escape sequences by the standard, but often
used in sed scripts.

src/regex/regcomp.c

index ccd3755b6367dab7e28c3615eabf3e5d630a89af..b3dbb25231cd55ec0b715fd41553619fffa9e6e9 100644 (file)
@@ -838,6 +838,9 @@ static reg_errcode_t parse_atom(tre_parse_ctx_t *ctx, const char *s)
                        s--;
                        break;
                case '{':
+               case '+':
+               case '?':
+                       /* extension: treat \+, \? as repetitions in BRE */
                        /* reject repetitions after empty expression in BRE */
                        if (!ere)
                                return REG_BADRPT;
@@ -993,7 +996,8 @@ static reg_errcode_t tre_parse(tre_parse_ctx_t *ctx)
                        }
                        if (*s=='\\' && ere)
                                break;
-                       if (*s=='\\' && s[1]!='{')
+                       /* extension: treat \+, \? as repetitions in BRE */
+                       if (*s=='\\' && s[1]!='+' && s[1]!='?' && s[1]!='{')
                                break;
                        if (*s=='\\')
                                s++;