Bug #5010
closedStatic base URI missing trailing slash for -xp command line option
100%
Description
In https://saxonica.plan.io/boards/5/topics/8210, Martin Honnen writes:
I have started to use Saxon JS 2.2's
xslt3 -xp
option to quickly run/test some XPath 3.1 stuff.One quirk that bugs me is shown below:
C:\Users\marti>xslt3 -xp:"static-base-uri()" "file://C:/Users/marti" C:\Users\marti>xslt3 -xp:"resolve-uri('foo.xml', static-base-uri())" "file:///C:/Users/foo.xml"
So I run
xslt3
in the directoryC:\Users\marti
andstatic-base-uri()
gives mefile://C:/Users/marti
without a trailing slash meaning any attempt to find a local file in the working directory with e.g.resolve-uri('foo.xml', static-base-uri())
fails to find the file as it looks in the parent directory forfile:///C:/Users/foo.xml
.A similar test with Saxon Java (using the XQuery command line API as it doesn't have an XPath one) gives
C:\Users\marti>java -cp "C:\Program Files\Saxonica\SaxonHE10-5J\saxon-he-10.5.jar" net.sf.saxon.Query -qs:"static-base-uri()" <?xml version="1.0" encoding="UTF-8"?>file:/C:/Users/marti/ C:\Users\marti>java -cp "C:\Program Files\Saxonica\SaxonHE10-5J\saxon-he-10.5.jar" net.sf.saxon.Query -qs:"resolve-uri('foo.xml', static-base-uri())" <?xml version="1.0" encoding="UTF-8"?>file:/C:/Users/marti/foo.xml
so there I get a static base URI with a trailing slash meaning files in the working directory are found when I resolve against the static base URI.
The problem with Saxon JS 2.2's base URI also arises with e.g.
xslt3 -xp:"doc('test2021052801.xml')"
, the named file exists in my working directory but Saxon gives an error as it looks in the parent directory:Error FODC0002 Cannot read file file:///C:/Users/test2021052801.xml - ENOENT: no such file or directory, open 'C:\Users\test2021052801.xml'
Updated by Debbie Lockett over 3 years ago
It looks like the bug is a simple mistake. The executeXPathOverData
function in command.js#694 assigns:
const staticBaseURI = filepathToUri(process["cwd"]() + "/");
but the trailing slash should be added after applying filepathToUri
rather than before, as in the -xsl
transform case (see the executeTransformation
function, command.js#426):
transformOptions['baseOutputURI'] = filepathToUri(process["cwd"]()) + "/";
The trailing slash is removed by path.resolve
, as used by NodeJSPlatform.fileURL
via filepathToUri
.
Updated by Debbie Lockett over 3 years ago
- Status changed from New to Resolved
- Assignee set to Debbie Lockett
- Fix Committed on JS Branch 2 added
Bug reproduced. Tests added in xp_test.js mocha test set (xp014 and xp015).
Fix committed in command.js to add trailing slash for staticBaseURI
after applying filepathToUri
(as described above).
Updated by Debbie Lockett over 3 years ago
- % Done changed from 0 to 100
- Fixed in JS Release set to Saxon-JS 2.3
Bug fix applied in the Saxon-JS 2.3 maintenance release.
Updated by Debbie Lockett over 3 years ago
- Status changed from Resolved to Closed
Please register to edit this issue
Also available in: Atom PDF Tracking page