Project

Profile

Help

Bug #3745

closed

file:path-to-uri() fails or works incorrectly with relative path and UNC

Added by T Hata about 6 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Saxon extensions
Sprint/Milestone:
-
Start date:
2018-04-14
Due date:
% Done:

100%

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

Description

http://www.saxonica.com/documentation/index.html#!functions/expath-file/path-to-uri

Transforms a file system path into a URI with the file:// scheme. If the path is relative, it is first resolved against the current working directory.

So, on Windows, put this file as C:\test dir\path-to-uri.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="#all" version="2.0" xmlns:file="http://expath.org/ns/file"
	xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:param as="xs:string" name="path" />
	<xsl:template name="main">
		<xsl:message select="'path=', $path" />
		<xsl:variable as="xs:anyURI" name="uri" select="file:path-to-uri($path)" />
		<xsl:message select="'uri=', $uri" />
		<xsl:sequence select="doc($uri)" />
	</xsl:template>
</xsl:stylesheet>

and verify that it works with a very simple relative path:

C:\test dir>dir /b path-to-uri.xsl
path-to-uri.xsl

C:\test dir>java -cp saxon9ee.jar net.sf.saxon.Transform -it:main -t -xsl:path-to-uri.xsl path="path-to-uri.xsl"
Saxon-EE 9.8.0.11J from Saxonica
Java version 1.8.0_161
...
Building tree for file:/C:/test%20dir/path-to-uri.xsl using class net.sf.saxon.tree.tiny.TinyBuilder
...

Looks good.

But file:path-to-uri() fails or returns unusable URI in the following cases:

Drive relative path

C:\test dir>dir /b c:path-to-uri.xsl
path-to-uri.xsl

C:\test dir>java -cp saxon9ee.jar net.sf.saxon.Transform -it:main -t -xsl:path-to-uri.xsl path="c:path-to-uri.xsl"
...
path= c:path-to-uri.xsl
java.io.IOException: The filename, directory name, or volume label syntax is incorrect
        at java.io.WinNTFileSystem.canonicalize0(Native Method)
        at java.io.WinNTFileSystem.canonicalize(Unknown Source)
        at java.io.File.getCanonicalPath(Unknown Source)
        at java.io.File.getCanonicalFile(Unknown Source)
        at com.saxonica.functions.extfn.EXPathFile.toFile(EXPathFile.java:1169)
        at com.saxonica.functions.extfn.EXPathFile.pathToUri(EXPathFile.java:1080)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.saxonica.expr.JavaExtensionFunctionCall.invokeMethod(JavaExtensionFunctionCall.java:828)
        at com.saxonica.expr.JavaExtensionFunctionCall.call(JavaExtensionFunctionCall.java:561)
        at com.saxonica.expr.JavaExtensionFunctionCall.iterate(JavaExtensionFunctionCall.java:438)
        at net.sf.saxon.expr.CardinalityChecker.evaluateItem(CardinalityChecker.java:280)
        at net.sf.saxon.expr.parser.ExpressionTool.evaluate(ExpressionTool.java:329)
        at net.sf.saxon.expr.LetExpression.eval(LetExpression.java:511)
        at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:692)
        at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:687)
        at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:151)
        at com.saxonica.ee.bytecode.ByteCodeCandidate.process(ByteCodeCandidate.java:141)
        at net.sf.saxon.expr.instruct.NamedTemplate.expand(NamedTemplate.java:265)
        at net.sf.saxon.Controller.callTemplate(Controller.java:2538)
        at net.sf.saxon.s9api.Xslt30Transformer.callTemplate(Xslt30Transformer.java:750)
        at net.sf.saxon.Transform.processFile(Transform.java:1252)
        at net.sf.saxon.Transform.doTransform(Transform.java:782)
        at net.sf.saxon.Transform.main(Transform.java:81)
Error at char 17 in xsl:variable/@select on line 7 column 78 of path-to-uri.xsl:
  IO error in file path:c:path-to-uri.xsl
IO error in file path:c:path-to-uri.xsl

Rooted relative path

C:\test dir>dir /b "\test dir\path-to-uri.xsl"
path-to-uri.xsl

C:\test dir>java -cp saxon9ee.jar net.sf.saxon.Transform -it:main -t -xsl:path-to-uri.xsl path="\test dir\path-to-uri.xsl"
...
path= \test dir\path-to-uri.xsl
uri= file:/C:/test%20dir/test%20dir/path-to-uri.xsl
URIResolver.resolve href="file:/C:/test%20dir/test%20dir/path-to-uri.xsl" base="file:/C:/test%20dir/path-to-uri.xsl"
Using parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
Error at char 4 in xsl:sequence/@select on line 9 column 38 of path-to-uri.xsl:
  FODC0002: I/O error reported by XML parser processing
  file:/C:/test%20dir/test%20dir/path-to-uri.xsl: C:\test dir\test dir\path-to-uri.xsl (The
  system cannot find the path specified)
I/O error reported by XML parser processing file:/C:/test%20dir/test%20dir/path-to-uri.xsl: C:\test dir\test dir\path-to-uri.xsl (The system cannot find the path specified)

UNC path

C:\test dir>dir /b "\\localhost\c$\test dir\path-to-uri.xsl"
path-to-uri.xsl

C:\test dir>java -cp saxon9ee.jar net.sf.saxon.Transform -it:main -t -xsl:path-to-uri.xsl path="\\localhost\c$\test dir\path-to-uri.xsl"
...
path= \\localhost\c$\test dir\path-to-uri.xsl
uri= file:/localhost/c$/test%20dir/path-to-uri.xsl
URIResolver.resolve href="file:/localhost/c$/test%20dir/path-to-uri.xsl" base="file:/C:/test%20dir/path-to-uri.xsl"
Using parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
Error at char 4 in xsl:sequence/@select on line 9 column 38 of path-to-uri.xsl:
  FODC0002: I/O error reported by XML parser processing
  file:/localhost/c$/test%20dir/path-to-uri.xsl: \localhost\c$\test dir\path-to-uri.xsl (The
  system cannot find the path specified)
I/O error reported by XML parser processing file:/localhost/c$/test%20dir/path-to-uri.xsl: \localhost\c$\test dir\path-to-uri.xsl (The system cannot find the path specified)

Related issues

Precedes Saxon - Bug #4280: Failure in file:base-dir(): "URI has an authority component"ClosedMichael Kay2018-04-162018-04-16

Actions

Please register to edit this issue

Also available in: Atom PDF