forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit8a29ed0
committed
Fix misoptimization of "{1,1}" quantifiers in regular expressions.
A bounded quantifier with m = n = 1 might be thought a no-op. Butaccording to our documentation (which traces back to Henry Spencer'soriginal man page) it still imposes greediness, or non-greediness in thecase of the non-greedy variant "{1,1}?", on whatever it's attached to.This turns out not to work though, because parseqatom() optimizes awaythe m = n = 1 case without regard for whether it's supposed to changethe greediness of the argument RE.We can fix this by just not applying the optimization when the greedinessneeds to change; the subsequent general cases handle it fine.The three cases in which we can still apply the optimization are(a) no quantifier, or quantifier does not impose a preference;(b) atom has no greediness property, implying it cannot match avariable amount of text anyway; or(c) quantifier's greediness is same as atom's.Note that in most cases where one of these applies, we'd have exitedearlier in the "not a messy case" fast path. I think it's now onlypossible to get to the optimization when the atom involves capturingparentheses or a non-top-level backref.Back-patch to all supported branches. I'd ordinarily be hesitant toput a subtle behavioral change into back branches, but in this caseit's very hard to see a reason why somebody would write "{1,1}?" unlessthey're trying to get the documented change-of-greediness behavior.Discussion:https://postgr.es/m/5bb27a41-350d-37bf-901e-9d26f5592dd0@charter.net1 parentd02768d commit8a29ed0
3 files changed
+63
-1
lines changedLines changed: 4 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1155 | 1155 |
| |
1156 | 1156 |
| |
1157 | 1157 |
| |
1158 |
| - | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
1159 | 1162 |
| |
1160 | 1163 |
| |
1161 | 1164 |
| |
|
Lines changed: 49 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
492 | 492 |
| |
493 | 493 |
| |
494 | 494 |
| |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
495 | 544 |
| |
496 | 545 |
| |
497 | 546 |
| |
|
Lines changed: 10 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
118 | 118 |
| |
119 | 119 |
| |
120 | 120 |
| |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
121 | 131 |
| |
122 | 132 |
| |
123 | 133 |
| |
|
0 commit comments
Comments
(0)