Bug #6318
closedreplace with curly braces in second argument gives error "Error FORX0002: Invalid XPath regular expression: '{' not allowed here"
100%
Description
The test case
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:template match="/" name="xsl:initial-template">
<test>
<run-with>{system-property('xsl:product-name')} {system-property('xsl:product-version')} {system-property('Q{http://saxon.sf.net/}platform')} at {current-dateTime()}</run-with>
<result>replace('15/01/24', '(.{2})/(.{2})/(.{2})', '$3$2$1'): {replace('15/01/24', '(.{2})/(.{2})/(.{2})', '$3$2$1')}</result>
</test>
</xsl:template>
</xsl:stylesheet>
when run with SaxonJS 2.6 both in the browser and from Node.js gives an unexpected and in my view wrong error message Invalid XPath regular expression: '{' not allowed here
.
Output from Node.js xslt3 -t -it
command:
SaxonJS 2.6 from Saxonica
Node.js version v18.18.1
Compiling stylesheet C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\replace-test-curly-braces\replace-curly-braces-test1.xsl
Stylesheet compilation time: 0.105s
Initial template: Q{http://www.w3.org/1999/XSL/Transform}initial-template
Asynchronous transform with options: stylesheetText={"N":"package","version":"30",(string), stylesheetBaseURI=file://C:/Users/marti/OneDrive(string), stylesheetParams=[object Object](string), outputProperties=[object Object](string), extraOptions=[object Object](string), destination=stdout(string), baseOutputURI=file://C:/Users/marti/OneDrive(string), logLevel=2(string), initialTemplate=Q{http://www.w3.org/1999/XSL/T(string),
SEF generated by SaxonJS 2.6 at 2024-01-15T11:47:32.329+01:00
<?xml version="1.0" encoding="UTF-8"?><test><run-with>SaxonJS 2.6 Node.js at 2024-01-15T11:47:32.383+01:00</run-with>Transformation failure: Error FORX0002 at replace-curly-braces-test1.xsl#9
Invalid XPath regular expression: '{' not allowed here
Error FORX0002 at replace-curly-braces-test1.xsl#9
Invalid XPath regular expression: '{' not allowed here
Saxon HE 12 Java runs the code just fine.
Updated by Martin Honnen about 1 year ago
The problem seems to be the sequence .{2}
, if I use something like [0-9]{2}
instead, SaxonJS evaluates it fine. But .{2}
ought to work.
Updated by Michael Kay about 1 year ago
Does the problem occur if the same regex is used outside the context of an AVT?
Updated by Martin Honnen about 1 year ago
Yes, Mike,
the same code without AVTs
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="no">
<xsl:template match="/" name="xsl:initial-template">
<test>
<run-with xsl:expand-text="yes">{system-property('xsl:product-name')} {system-property('xsl:product-version')} {system-property('Q{http://saxon.sf.net/}platform')} at {current-dateTime()}</run-with>
<result>replace('15/01/24', '(.{2})/(.{2})/(.{2})', '$3$2$1'): <xsl:value-of select="replace('15/01/24', '(.{2})/(.{2})/(.{2})', '$3$2$1')"/></result>
</test>
</xsl:template>
</xsl:stylesheet>
still gives
Transformation failure: Error FORX0002 at replace-curly-braces-test3.xsl#9
Invalid XPath regular expression: '{' not allowed here
Error FORX0002 at replace-curly-braces-test3.xsl#9
Invalid XPath regular expression: '{' not allowed here
Updated by Michael Kay about 1 year ago
Looks like a simple parsing error: in the case '.'
branch at regex.js line 372, it should set allowOpenCurly
to true, as it does for example after )
or ]
.
I suspect this should also be set on the case ' '
(whitespace) branch on line 392.
(This code is parsing an XPath regex to convert it into a Javascript regex).
Updated by Debbie Lockett 12 months ago
Added qt3tests test fn-replace-59
. (See pull request https://github.com/w3c/qt3tests/pull/57. I unintentionally added this commit to a pull request which was already open.)
Updated by Debbie Lockett 12 months ago
- Status changed from New to Resolved
- Fix Committed on JS Branch 2, Trunk added
Fix committed on main and saxonjs2 branches, so the new QT3 test fn-replace-59
now passes. I have made precisely the changes suggested by Mike in comment #note-4 (i.e. without any further review).
Updated by Debbie Lockett 3 months ago
- Status changed from Resolved to Closed
- % Done changed from 0 to 100
- Fixed in JS Release set to SaxonJS 2.7
Bug fix applied in the SaxonJS 2.7 maintenance release.
Please register to edit this issue
Also available in: Atom PDF Tracking page