Bug #2390
closedWrong result from replace()
100%
Description
From Gerrit Imsieke on saxon:help list:
In PE 9.6.0.5, this expression:
replace('abc', '^.+?(b+)?$', '$1')
gives the unexpected result 'b' instead of ''.
Updated by Michael Kay over 9 years ago
- Status changed from New to In Progress
What happens is that ^ gets matched, then .+? matches 'a', then (b+)? matches 'b' (setting the value of $1), then $ doesn't match; so it backtracks, and this time finds a greedier match on .+? which doesn't require (b+)? to match anything. But the backtracking makes no attempt to clear the value of $1.
This one is going to be somewhat tricky.
One possible approach is that when you backtrack to position N, all groups that start (or finish?) after position N should be scrubbed.
Updated by Michael Kay over 9 years ago
I've implemented that suggestion for OpReluctantFixed only (each time the operator is invoked, before attempting any matching, it clears any captured groups starting at or beyond the current position). It achieves the desired effect in this test case. It needs regression testing, Need to consider whether any other operators are affected.
Updated by Michael Kay over 9 years ago
- Status changed from In Progress to Resolved
Test case replace-47 added to QT3. All replace() tests pass. Committing the fix on the 9.6 and 9.7 branches.
Updated by Michael Kay over 9 years ago
- Status changed from Resolved to In Progress
Reopening. The same problem occurs for the Choice operator:
replace('abcd', '^a(.).$|^a...$', '$1')
(QT3 test case fn-replace-48 added)
Updated by Michael Kay over 9 years ago
- Status changed from In Progress to Resolved
Added a similar fix to the Choice operator. Closing as resolved.
Updated by O'Neil Delpratt over 9 years ago
- Status changed from Resolved to Closed
- % Done changed from 0 to 100
- Fixed in version set to 9.6.0.6
Bug fix applied in the Saxon 9.6.0.6 maintenance release.
Updated by O'Neil Delpratt almost 9 years ago
- Sprint/Milestone set to 9.6.0.6
- Applies to branch 9.6 added
- Fix Committed on Branch 9.6 added
- Fixed in Maintenance Release 9.6.0.6 added
Please register to edit this issue