فهرست منبع

regex: treat \+, \? as repetitions in BRE

These are undefined escape sequences by the standard, but often
used in sed scripts.
Szabolcs Nagy 10 سال پیش
والد
کامیت
25160f1c08
1فایلهای تغییر یافته به همراه5 افزوده شده و 1 حذف شده
  1. 5 1
      src/regex/regcomp.c

+ 5 - 1
src/regex/regcomp.c

@@ -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++;