aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-11-05 21:09:53 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-11-05 21:09:53 +0100
commite251c6463913bcd7c9c40b4dc168010f6de68b5a (patch)
treea8d2cfcfa09de64d86b10f1a6137373b553f078b /src/main.c
parent436557eca3da4492def86d5ef8c2d84c5d1c3e71 (diff)
Check for whitespace after regex using islbrk()
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index 89e3007..120a88e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -330,14 +330,13 @@ pattern_comp(u8view_t pat)
reopts |= PCRE2_UCP;
for (;;) {
- if (ucsgnext(&g, &pat) == 0)
+ if (ucsgnext(&g, &pat) == 0 || islbrk(g))
break;
- if (g.len != 1)
- goto bad_flag;
- if (uprop_is_pat_ws(*g.p))
+ int w = ucsnext(&ch, &g);
+ if (uprop_is_pat_ws(ch))
break;
- switch (*g.p) {
+ switch (ch) {
case 'i': reopts |= PCRE2_CASELESS; break;
case 'I': reopts &= ~PCRE2_CASELESS; break;
case 'l': reopts |= PCRE2_LITERAL; break;
@@ -345,7 +344,7 @@ pattern_comp(u8view_t pat)
case 'u': reopts |= PCRE2_UCP; break;
case 'U': reopts &= ~PCRE2_UCP; break;
default:
- bad_flag:
+ VSHFT(&g, -w);
cerr(EXIT_FATAL, "Unknown regex flag %s%.*s%s",
lquot, SV_PRI_ARGS(g), rquot);
}