Project

Profile

Help

Bug #4076

closed

fn:replace() with unmatched double digit capturing group

Added by Debbie Lockett over 5 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Normal
Category:
XPath conformance
Sprint/Milestone:
-
Start date:
2018-12-20
Due date:
% Done:

100%

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

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.

Please register to edit this issue

Also available in: Atom PDF