ref: 5ba75dac6b53f05897af437eecf909fabbbf5a3d
parent: 15795e2b58fcb6e801c401795d40c1344517b5ee
author: Tor Andersson <[email protected]>
date: Thu Oct 9 12:14:18 EDT 2014
Allow identity escapes in regular expressions.
--- a/regex.c
+++ b/regex.c
@@ -99,6 +99,11 @@
#define ESCAPES "BbDdSsWw^$\\.*+?()[]{}|0123456789"
+static int isunicodeletter(int c)
+{
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || isalpharune(c);
+}
+
static int nextrune(struct cstate *g)
{
g->source += chartorune(&g->yychar, g->source);
@@ -133,9 +138,11 @@
}
return 0;
}
- if (!strchr(ESCAPES, g->yychar))
+ if (strchr(ESCAPES, g->yychar))
+ return 1;
+ if (isunicodeletter(g->yychar) || g->yychar == '_') /* check identity escape */
die(g, "invalid escape character");
- return 1;
+ return 0;
}
return 0;
}
@@ -295,8 +302,7 @@
g->yychar = '\b';
else if (g->yychar == '0')
g->yychar = 0;
- else
- die(g, "invalid escape character");
+ /* else identity escape */
}
if (havesave) {
if (havedash) {