Bug #2390
closed
Wrong result from replace()
Category:
XPath conformance
Fix Committed on Branch:
9.6
Fixed in Maintenance Release:
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 ''.
- 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.
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.
- 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.
- 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)
- Status changed from In Progress to Resolved
Added a similar fix to the Choice operator. Closing as resolved.
- 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.
- 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
Also available in: Atom
PDF