Bug #4076
closedfn:replace() with unmatched double digit capturing group
100%
Description
The wrong result is returned from fn:replace() when the supplied replacement string contains reference $N
with N > 9, but the Nth parenthesized subexpression in the pattern is not matched.
This is apparently a longstanding bug - I have tested with Saxon 9.5 onwards and get the same (incorrect) results.
Issue and example code raised on saxon-help list:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
exclude-result-prefixes="xs math"
version="2.0">
<xsl:template match="/">
<!--<xsl:value-of select="replace('CREDIT1_INLINE', '^(((IMG|BOX|TABLE)|(CREDIT)(\d*))_)?(((.*?)([_]?(HALF_RIGHT|HALF|WIDE_RIGHT|RIGHT|FULL|INLINE|PREMIUM)[_]?)(.*?))|(.+))$', '$4$5$8$11$12', 'i')"/>-->
<xsl:value-of select="replace('987654321A', '^(9)(8)(7)(6)(5)(4)(3)(2)(1)((A*?)|(.+))$', '$9$11$12', 'i')"/>
</xsl:template>
</xsl:stylesheet>
On Saxon-B 9.1.0.8, the result is "1A". This is the expected result.
On Saxon-HE 9.9.0.1, the result is "1A92". This result is not expected: It seems like the $12
is not treated as reference to group #12
(which, albeit not matching any content and hence being empty, exists in the regex), but as reference to group "$1" (='9')
, followed by the literal '2'.
The commented-out line is an actual call in my transformation with expected result "CREDIT1", but yielding "CREDIT1CREDIT1_2" in HE 9.9.0.1.
Updated by Debbie Lockett over 5 years ago
- Status changed from New to Resolved
- Applies to branch deleted (
9.7) - Fix Committed on Branch 9.8, 9.9 added
Patch committed on 9.9 and 9.8 branches.
For the maxCapture
limit in REMatcher.replace()
, use program.maxParens
(from the REMatcher's associated REProgram), which gives the count of parenthesized subexpressions in the pattern; rather than getParenCount()
which gives the number of matched capturing groups.
Test fn-replace-57 added to the QT3 test suite.
Updated by O'Neil Delpratt over 5 years ago
- % Done changed from 0 to 100
- Fixed in Maintenance Release 9.9.1.1 added
Bug fix applied to the Saxon 9.9.1.1 maintenance release.
Updated by O'Neil Delpratt almost 5 years ago
- Status changed from Resolved to Closed
Please register to edit this issue