forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit65dc30c
committed
Fix regexp misbehavior with capturing parens inside "{0}".
Regexps like "(.){0}...\1" drew an "invalid backreference number".That's not unreasonable on its face, since the capture group willnever be matched if it's iterated zero times. However, other enginessuch as Perl's don't complain about this, nor do we throw an error forrelated cases such as "(.)|\1", even though that backref can neversucceed either. Also, if the zero-iterations case happens at runtimerather than compile time --- say, "(x)*...\1" when there's no "x" tobe found --- that's not an error, we just deem the backref to notmatch. Making this even less defensible, no error was thrown fornested cases such as "((.)){0}...\2"; and to add insult to injury,those cases could result in assertion failures instead. (It seemsthat nothing especially bad happened in non-assert builds, though.)Let's just fix it so that no error is thrown and instead the backrefis deemed to never match, so that compile-time detection of noiterations behaves the same as run-time detection.Per report from Mark Dilger. This appears to be an aboriginal errorin Spencer's library, so back-patch to all supported versions.Pre-v14, it turns out to also be necessary to back-patch one aspect ofcommitscb76fbd/00116dee5, namely to create capture-node subREs withthe begin/end states of their subexpressions, not the current lp/rpof the outer parseqatom invocation. Otherwise delsub complains thatwe're trying to disconnect a state from itself. This is a bit scarybut code examination shows that it's safe: in the pre-v14 code, if wewant to wrap iteration around the subexpression, the first thing we dois overwrite the atom's begin/end fields with new states. So thebogus values didn't survive long enough to be used for anything, exceptif no iteration is required, in which case it doesn't matter.Discussion:https://postgr.es/m/A099E4A8-4377-4C64-A98C-3DEDDC075502@enterprisedb.com1 parent1046a69 commit65dc30c
File tree
5 files changed
+69
-5
lines changed- src
- backend/regex
- test
- modules/test_regex
- expected
- sql
- regress
- expected
- sql
5 files changed
+69
-5
lines changedLines changed: 17 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1089 | 1089 |
| |
1090 | 1090 |
| |
1091 | 1091 |
| |
1092 |
| - | |
1093 |
| - | |
1094 |
| - | |
1095 |
| - | |
1096 |
| - | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
1097 | 1109 |
| |
1098 | 1110 |
| |
1099 | 1111 |
| |
|
Lines changed: 22 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3576 | 3576 |
| |
3577 | 3577 |
| |
3578 | 3578 |
| |
| 3579 | + | |
| 3580 | + | |
| 3581 | + | |
| 3582 | + | |
| 3583 | + | |
| 3584 | + | |
| 3585 | + | |
| 3586 | + | |
| 3587 | + | |
| 3588 | + | |
| 3589 | + | |
| 3590 | + | |
| 3591 | + | |
| 3592 | + | |
| 3593 | + | |
| 3594 | + | |
| 3595 | + | |
| 3596 | + | |
| 3597 | + | |
| 3598 | + | |
| 3599 | + | |
| 3600 | + | |
3579 | 3601 |
| |
3580 | 3602 |
| |
3581 | 3603 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1036 | 1036 |
| |
1037 | 1037 |
| |
1038 | 1038 |
| |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
1039 | 1045 |
| |
1040 | 1046 |
| |
1041 | 1047 |
| |
|
Lines changed: 19 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
567 | 567 |
| |
568 | 568 |
| |
569 | 569 |
| |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
570 | 589 |
| |
571 | 590 |
| |
572 | 591 |
| |
|
Lines changed: 5 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
135 | 135 |
| |
136 | 136 |
| |
137 | 137 |
| |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
138 | 143 |
| |
139 | 144 |
| |
140 | 145 |
| |
|
0 commit comments
Comments
(0)