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

Commitf69c01f

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 parent788e35a commitf69c01f

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
@@ -944,7 +944,7 @@ parseqatom(struct vars * v,
944944
EMPTYARC(lp,s);
945945
EMPTYARC(s2,rp);
946946
NOERR();
947-
atom=parse(v,')',PLAIN,s,s2);
947+
atom=parse(v,')',type,s,s2);
948948
assert(SEE(')')||ISERR());
949949
NEXT();
950950
NOERR();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,8 @@ select 'a' ~ '()+\1';
321321
t
322322
(1 row)
323323

324+
-- Error conditions
325+
select 'xyz' ~ 'x(\w)(?=\1)'; -- no backrefs in LACONs
326+
ERROR: invalid regular expression: invalid backreference number
327+
select 'xyz' ~ 'x(\w)(?=(\1))';
328+
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
@@ -82,3 +82,7 @@ select 'a' ~ '$()|^\1';
8282
select'a' ~'.. ()|\1';
8383
select'a' ~'()*\1';
8484
select'a' ~'()+\1';
85+
86+
-- Error conditions
87+
select'xyz' ~'x(\w)(?=\1)';-- no backrefs in LACONs
88+
select'xyz' ~'x(\w)(?=(\1))';

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp