Skip to content
Tcl Source Code History Of Ticket a6029e
Login

History Of Ticket a6029e

Artifacts Associated With Ticket a6029e

  1. Ticket change [f60cd72d52] (rid 257495) by serhiy.storchaka on 2026-10-10 18:47:21:

    1. cmimetype initialized to: "text/x-fossil-wiki"
    2. comment initialized to:
      These never return:
      <verbatim>
      regexp {(b*)a\1|\1} ba      ;# should return 1 (matches "a")
      regexp {$()|^\1} a          ;# should return 0
      regexp {.. ()|\1} a         ;# should return 0
      regexp {()*\1} a            ;# should return 1
      </verbatim>
      The first one was found by comparing random patterns with backreferences against PostgreSQL; the other three are from the PostgreSQL regression tests.
      
      <tt>complicatedFindLoop()</tt> asks the search DFA for the earliest possible match end <tt>close</tt>, tries every start point up to it, and when all of them fail, searches again from the same <tt>close</tt>. The DFA treats a backreference as matching anything, so it reports a possible empty match there again, and the loop never advances. This is only possible with backreferences. It started with the fix for [6585b21ca8] in 8.6.1; <tt>()*\1</tt> hangs since 8.6.5.
      
      PostgreSQL fixed this in 2015, after the same change, in [https://github.com/postgres/postgres/commit/f2c4ffc330|commit f2c4ffc330]: advance <tt>close</tt> after a failed range (<tt>close++</tt>), and in <tt>citerdissect()</tt> try a real iteration before accepting zero iterations of an empty match, so that <tt>()*\1</tt> matches instead of failing. This fix was not included in the regexp bundle [497b93405b]. With both changes ported, all four examples give the PostgreSQL results, and the regexp tests pass.
      
    3. foundin initialized to: "8.6.18, 9.0.5, 9.1.0"
    4. login: "serhiy.storchaka"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. severity initialized to: "Important"
    8. status initialized to: "Open"
    9. submitter initialized to: "serhiy.storchaka"
    10. subsystem initialized to: "43. Regexp"
    11. title initialized to:
      regexp hangs with backreferences when a possible empty match fails
      
    12. type initialized to: "Bug"
  2. Ticket change [0b5eed668e] (rid 257510) by serhiy.storchaka on 2026-10-10 19:29:32:

    1. icomment:
      Proposed fix in branch [/timeline?r=regexp-backref-search-loop|regexp-backref-search-loop]: the port of PostgreSQL commit f2c4ffc330. Tests reg-14.32 to 14.36 (the four examples and <tt>()+\1</tt>).
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"
  3. Ticket change [2ccfa0e829] (rid 258421) by serhiy.storchaka on 2026-10-17 07:16:33:

    1. icomment:
      Merged into main in [ac36095ed4], not yet into 9.0 and 8.6. Besides the hang, it also changes which groups are set when an iteration matches an empty string: the engine now prefers one empty iteration to zero (as PostgreSQL does), so <nowiki>[regexp -indices -inline {((a?)*|(b?)*)+} aaa]</nowiki> gives <nowiki>{0 2} {3 2} {3 2} {-1 -1}</nowiki> on main, as in 8.4 to 8.6.4, and <nowiki>{0 2} {3 2} {-1 -1} {-1 -1}</nowiki> in 8.6.5 to 9.0 (since [c8dfe06653]).
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"