Bug #3609
closedRegex capturing group ignored on .NET
100%
Description
Reported by user:
regex problem in Saxon-HE 9.8.0.7N (and possibly other versions).
When using the native .NET regex engine (using the ";n" flag), capturing groups seem to be ignored.
Here is a style sheet that isolates the issue:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:variable name="input" select="'abc'"/>
<xsl:variable name="pattern" select="'a(.)c'"/>
<xsl:variable name="replacement" select="'x$1z'"/>
<xsl:template match="/">
<data>
<test><xsl:value-of select="replace($input, $pattern, $replacement)"/> (default)</test>
<test><xsl:value-of select="replace($input, $pattern, $replacement, ';j')"/> (Java)</test>
<test><xsl:value-of select="replace($input, $pattern, $replacement, ';n')"/> (.NET)</test>
</data>
</xsl:template>
</xsl:stylesheet>
When executed (on Windows 7, using ASP.NET or the Transform.exe tool) I get:
<data>
<test>xbz (default)</test>
<test>xbz (Java)</test>
<test>xz (.NET)</test>
</data>
The capturing group syntax should be valid on .NET as well:
There is, however, an option called ExplicitCapture that disables capturing with plain parentheses:
https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-options
I couldn't help noticing that this option is activated with a .NET specific flag "n".
Updated by O'Neil Delpratt over 6 years ago
Problem reproduced. There seems to be a bug here.
Updated by O'Neil Delpratt over 6 years ago
- Status changed from New to In Progress
There seems to be something else going wrong with the regex group capture.
I tried removing the flags argument from fn:replace and set the default regex engine on the processor as follows:
proc.SetProperty("http://saxon.sf.net/feature/defaultRegexEngine", "N");
We get the same result.
Updated by O'Neil Delpratt over 6 years ago
- Status changed from In Progress to Resolved
- % Done changed from 0 to 100
- Fix Committed on Branch 9.8, trunk added
Bug fixed in the DotNetRegularExpression. The problem was we were not setting the groupCount variable.
The logic to this is given in F+O section 5.6.4 (see: https://www.w3.org/TR/xpath-functions-31/#func-replace)
Updated by O'Neil Delpratt about 6 years ago
- Status changed from Resolved to Closed
- Fixed in Maintenance Release 9.8.0.8 added
Bug fix applied in the Saxon 9.8.0.8 maintenance release.
Please register to edit this issue