Project

Profile

Help

Bug #2390

closed

Wrong result from replace()

Added by Michael Kay almost 9 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
XPath conformance
Sprint/Milestone:
Start date:
2015-06-03
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
9.6
Fix Committed on Branch:
9.6
Fixed in Maintenance Release:
Platforms:

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 ''.

Actions #1

Updated by Michael Kay almost 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.

Actions #2

Updated by Michael Kay almost 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.

Actions #3

Updated by Michael Kay almost 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.

Actions #4

Updated by Michael Kay almost 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)

Actions #5

Updated by Michael Kay almost 9 years ago

  • Status changed from In Progress to Resolved

Added a similar fix to the Choice operator. Closing as resolved.

Actions #6

Updated by O'Neil Delpratt almost 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.

Actions #7

Updated by O'Neil Delpratt over 8 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

Also available in: Atom PDF