Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita43b4ab

Browse files
committed
Fix enforcement of restrictions inside regexp lookaround constraints.
Lookahead and lookbehind constraints aren't allowed to contain backrefs,and parentheses within them are always considered non-capturing. Or sosays the manual. But the regexp parser forgot about these rules onceinside a parenthesized subexpression, so that constructs like (\w)(?=(\1))were accepted (but then not correctly executed --- a case like this actedlike (\w)(?=\w), without any enforcement that the two \w's match the sametext). And in (?=((foo))) the innermost parentheses would be counted ascapturing parentheses, though no text would ever be captured for them.To fix, properly pass down the "type" argument to the recursive invocationof parse().Back-patch to all supported branches; it was agreed that silentmisexecution of such patterns is worse than throwing an error, even thoughnew errors in minor releases are generally not desirable.
1 parent8d7396e commita43b4ab

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

‎src/backend/regex/regcomp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ parseqatom(struct vars * v,
951951
EMPTYARC(lp,s);
952952
EMPTYARC(s2,rp);
953953
NOERR();
954-
atom=parse(v,')',PLAIN,s,s2);
954+
atom=parse(v,')',type,s,s2);
955955
assert(SEE(')')||ISERR());
956956
NEXT();
957957
NOERR();

‎src/test/regress/expected/regex.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,8 @@ select 'a' ~ '()+\1';
490490
t
491491
(1 row)
492492

493+
-- Error conditions
494+
select 'xyz' ~ 'x(\w)(?=\1)'; -- no backrefs in LACONs
495+
ERROR: invalid regular expression: invalid backreference number
496+
select 'xyz' ~ 'x(\w)(?=(\1))';
497+
ERROR: invalid regular expression: invalid backreference number

‎src/test/regress/sql/regex.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,7 @@ select 'a' ~ '$()|^\1';
117117
select'a' ~'.. ()|\1';
118118
select'a' ~'()*\1';
119119
select'a' ~'()+\1';
120+
121+
-- Error conditions
122+
select'xyz' ~'x(\w)(?=\1)';-- no backrefs in LACONs
123+
select'xyz' ~'x(\w)(?=(\1))';

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp