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

Appearance settings

Commit a43b4ab

Browse filesBrowse 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 so says the manual. But the regexp parser forgot about these rules once inside a parenthesized subexpression, so that constructs like (\w)(?=(\1)) were accepted (but then not correctly executed --- a case like this acted like (\w)(?=\w), without any enforcement that the two \w's match the same text). And in (?=((foo))) the innermost parentheses would be counted as capturing parentheses, though no text would ever be captured for them. To fix, properly pass down the "type" argument to the recursive invocation of parse(). Back-patch to all supported branches; it was agreed that silent misexecution of such patterns is worse than throwing an error, even though new errors in minor releases are generally not desirable.
1 parent 8d7396e commit a43b4ab
Copy full SHA for a43b4ab

File tree

Expand file treeCollapse file tree

3 files changed

+10
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+10
-1
lines changed

‎src/backend/regex/regcomp.c

Copy file name to clipboardExpand all lines: src/backend/regex/regcomp.c
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/test/regress/expected/regex.out
+5Lines 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

Copy file name to clipboardExpand all lines: src/test/regress/sql/regex.sql
+4Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.