Project

Profile

Help

Bug #5010

closed

Static base URI missing trailing slash for -xp command line option

Added by Debbie Lockett over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Category:
Command line
Sprint/Milestone:
-
Start date:
2021-05-28
Due date:
% Done:

100%

Estimated time:
Applies to JS Branch:
2
Fix Committed on JS Branch:
2
Fixed in JS Release:
SEF Generated with:
Platforms:
Company:
-
Contact person:
-
Additional contact persons:
-

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 directory C:\Users\marti and static-base-uri() gives me file://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 for file:///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'
Actions #1

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.

Actions #2

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).

Actions #3

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.

Actions #4

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