|
2026-10-11
| ||
| 16:50 | • Closed ticket [75c9d9cece]: regexp sometimes allows an invalid backref to be mat... artifact: 32c83197f2 user: jan.nijtmans | |
| 16:45 | Fix [75c9d9cece]: regexp sometimes allows an invalid backref to be matched check-in: 52c73e7244 user: jan.nijtmans tags: core-8-6-branch | |
| 16:34 | Fix [75c9d9cece]: regexp sometimes allows an invalid backref to be matched check-in: 0e954b3c59 user: jan.nijtmans tags: core-9-0-branch | |
|
2026-10-10
| ||
| 22:30 | Fix [75c9d9cece]: regexp sometimes allows an invalid backref to be matched check-in: 9383b0c913 user: jan.nijtmans tags: trunk, main | |
| 19:29 | • Ticket [75c9d9cece] regexp sometimes allows an invalid backref to be matched... artifact: 49e6151252 user: serhiy.storchaka | |
| 19:25 | Match Tom Lane's patch for [75c9d9cece] fully: clear the match data once in exec() instead of before... closed check-in: dc136f42c0 user: serhiy.storchaka tags: regexp-backref-failed-alt | |
| 19:09 | Fix [75c9d9cece]: a backreference could match a capture left over from a failed alternative. Clear t... check-in: edfdd1cc8d user: serhiy.storchaka tags: regexp-backref-failed-alt | |
|
2021-08-23
| ||
| 16:04 | • New ticket [75c9d9cece] regexp sometimes allows an invalid backref to be matched... artifact: 81796d5021 user: tgl | |
regexp sometimes allows an invalid backref to be matched
Closed / Fixed75c9d9cece5612408603f4e56773f55ada24b2d7Created 5 years agoUpdated 52 days ago
Descriptionplain2021-08-23 16:04:19
$ tclsh
% regexp {^(.)\1|\1.} {abcdef}
1
% regexp {^((.)\2|..)\2} {abadef}
1
Of course, neither of these should match, because the (.) capture is within a failed alternative branch,
so the last backref to it should be deemed unable to match.
Analysis and fix for it in Postgres is here:
https://www.postgresql.org/message-id/151435.1629733387%40sss.pgh.pa.us
I doubt you can use the code change exactly as-is, because I don't think you ever adopted our changes
to create an explicit "iteration" subre type. But the principle, and particularly the more careful
specification of cdissect's recursion rules, should still work for you.
Referenced by5
52c73e7244Fix [75c9d9cece]: regexp sometimes allows an invalid backref to be matched check-in2026-10-11 16:45:590e954b3c59Fix [75c9d9cece]: regexp sometimes allows an invalid backref to be matched check-in2026-10-11 16:34:219383b0c913Fix [75c9d9cece]: regexp sometimes allows an invalid backref to be matched check-in2026-10-10 22:30:29dc136f42c0Match Tom Lane's patch for [75c9d9cece] fully: clear the match data once in exec() instead of before each cdissect() call and at each new midpoint, and restore his comments. check-in2026-10-10 19:25:56edfdd1cc8dFix [75c9d9cece]: a backreference could match a capture left over from a failed alternative. Clear the left side's captures when the right side of a concatenation fails, and document the cdissect() rules, as in PostgreSQL. New tests reg-14.30, 14.31. check-in2026-10-10 19:09:23
serhiy.storchakawiki2026-10-10 19:29:32
Still the same in 8.6, 9.0 and 9.1. When the right side of a concatenation failed, ccondissect() and crevcondissect() left the captures of the left side set, so the next alternative's backref saw them.
Proposed fix in branch regexp-backref-failed-alt: your PostgreSQL change, which clears the left side's captures when the right side fails and defines the cdissect() rules for clearing match data. Tests reg-14.30 and 14.31 (your examples).
jan.nijtmanswiki2026-10-11 16:50:48
Fixed in [trunk], core-9-0-branch and core-8-6-branch
Many thanks!
Log in (anonymous is fine) to add a comment.