andgineer / TRegExpr

Regular expressions (regex), pascal.
https://regex.sorokin.engineer/en/latest/
MIT License
174 stars 63 forks source link

Fix recursion #325

Closed User4martin closed 1 year ago

User4martin commented 1 year ago

Fix #324 comment 1. Subsequent (side-by-side) recursive calls did see data captured in previous calls. Improve speed.

Include existing PR #323 and #322

@Alexey-T

All tests work for the old and new recursion behaviour. Except

IsMatching('2nd recurse does NOT see capture from earlier recurse',
             '[aA](?R)?(?:X|([bcBC]))(?R)?\1',
             'aABBcAXBc',  [2,3,  3,1]);

  IsMatching('2nd recurse does NOT see capture from earlier recurse',
             '[aA]((?R))?(?:X|([bcBC]))((?R))?\2',
             'aABBcAXBc',  [2,3,  -1,-1,  3,1,  -1,-1]);

Which are specially crafted to exploit the issue in the old behaviour

Alexey-T commented 1 year ago

@andgineer Pls apply.

andgineer commented 1 year ago

could you resolve the conflicts?

User4martin commented 1 year ago

Will do...

Can you check https://github.com/User4martin/TRegExpr/commit/more-references Can that be added? https://regex101.com/r/7qgquy/1

(and one other fix coming up)

Alexey-T commented 1 year ago

Can that be added? https://regex101.com/r/7qgquy/1

It must be discussed in a new topic. with detailed description: what was not ok, what you propose...

User4martin commented 1 year ago

Added #326 Added fix for "literal {" mode

Alexey-T commented 1 year ago

Write to history block ending: "by Martin Friebe." Better increase version to 1.167.

User4martin commented 1 year ago

Added another fix. Checking fixed length of a look-behind would fail if the look-behind had certain reference or sub-calls. (Because the HasFixedLength would increment the pointer to the next OP, but not skip the index stored after the command.)

Alexey-T commented 1 year ago

docs:

``\k`name```

Did you make mistake - backtick instead of single quote?

User4martin commented 1 year ago

@Alexey-T

Alexey-T commented 1 year ago

Good, tkx.

 (GrpBounds[0].GrpEnd[Idx] > GrpBounds[0].GrpStart[Idx])

maybe better >= ?

User4martin commented 1 year ago

Good, tkx.

 (GrpBounds[0].GrpEnd[Idx] > GrpBounds[0].GrpStart[Idx])

maybe better >= ?

That is in TRegExpr.GetMatch ?

If it is equal, then the result is an empty string. And it has already been set to empty.

Alexey-T commented 1 year ago

Ok, indeed.

Alexey-T commented 1 year ago

@andgineer Please apply?