Project

Profile

Help

Bug #6273

closed

White space in file path causing an error.

Added by Daniel Haley 3 months ago. Updated about 1 month ago.

Status:
Closed
Priority:
Low
Category:
C++ API
Start date:
2023-12-01
Due date:
% Done:

100%

Estimated time:
Found in version:
12.4
Fixed in version:
12.4.2
Platforms:

Description

Possibly related to: https://saxonica.plan.io/issues/6143

I'm seeing differences in how spaces in paths are handled between 12.3.0 and 12.4.1. Especially with stylesheet_file, input_file, and output_file args.

Here is a sample Python. The stylesheet ident.xsl is just a 3.0 identity transform (<xsl:mode on-no-match="shallow-copy"/>) and ident.xml is just <foo/>.

Python (3.11.6 on Windows 10)

import os
from pathlib import Path
from saxonche import *

with PySaxonProcessor(license=False) as proc:
    print(f"Processor version: {proc.version}")

    xsltproc = proc.new_xslt30_processor()

    executable = xsltproc.compile_stylesheet(stylesheet_file=r"C:\Users\Dan Haley\Desktop\try_saxon\ident.xsl")

    results = executable.transform_to_string(source_file=r"C:\Users\Dan Haley\Desktop\try_saxon\ident.xml")

    print(results)

Saxon 12.4

Doesn't work:

  • r"C:\Users\Dan Haley\Desktop\try_saxon\ident.xsl"
  • "file:///C:/Users/Dan%20Haley/Desktop/try_saxon/ident.xsl"
  • "C:/Users/Dan Haley/Desktop/try_saxon/ident.xsl"
  • "C:/Users/Dan%20Haley/Desktop/try_saxon/ident.xsl"
  • Path(r"C:\Users\Dan Haley\Desktop\try_saxon", "ident.xsl").absolute().as_uri()

Works:

  • "file:///C:/Users/Dan Haley/Desktop/try_saxon/ident.xsl"

Saxon 12.3

Doesn't work:

  • "file:///C:/Users/Dan Haley/Desktop/try_saxon/ident.xsl"

Works:

  • r"C:\Users\Dan Haley\Desktop\try_saxon\ident.xsl"
  • "file:///C:/Users/Dan%20Haley/Desktop/try_saxon/ident.xsl"
  • "C:/Users/Dan Haley/Desktop/try_saxon/ident.xsl"
  • "C:/Users/Dan%20Haley/Desktop/try_saxon/ident.xsl"
  • Path(r"C:\Users\Dan Haley\Desktop\try_saxon", "ident.xsl").absolute().as_uri()

I did notice that in the exception the space seems like it's getting double percent encoded; a single space is encoded as %2520 (like " " -> %20 -> %2520):


Files

clipboard-202312011605-jrtcw.png (43.8 KB) clipboard-202312011605-jrtcw.png Daniel Haley, 2023-12-02 00:05
Actions #1

Updated by Martin Honnen 3 months ago

Let's wait for what O'Neil has to say, unfortunately the SaxonC 12.4 branch doesn't seem to be online yet at https://saxonica.plan.io/projects/saxonmirrorhe/repository/he?utf8=%E2%9C%93&rev=saxon12.

In an experiment of my own I managed all the following to run from Windows and Linux:

from saxonche import PySaxonProcessor, PySaxonApiError

from pathlib import Path

with PySaxonProcessor() as saxon_proc:
    print(saxon_proc.version)

    xslt_processor = saxon_proc.new_xslt30_processor()

    filenames = [r'sample1 sheet.xsl', r'dir space test\sample1 sheet.xsl', r'dir space test/sample1 sheet.xsl']
    filenames.extend([Path(filename).as_posix() for filename in filenames])

    for filename in filenames:
        try:
            print(f'Running {filename}:')
            xslt_executable = xslt_processor.compile_stylesheet(stylesheet_file=filename)
            print(xslt_executable.call_template_returning_string())
        except PySaxonApiError as e:
            print(e.message)
        print()

Windows output:

(venv) PS C:\Users\marti\PycharmProjects\SaxonCHE124FilePathWithSpaces> python .\main.py
SaxonC-HE 12.4 from Saxonica
Running sample1 sheet.xsl:
<p>Run with SAXON HE 12.4 at 2023-12-02T07:51:07.1600576+01:00; static-base-uri: file:///C:/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/sample1%20sheet.xsl</p><!--Run with SAXON HE 12.4 at 2023-12-02T07:51:07.1600576+01:00; static-base-uri: file:///C:/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/sample1%20sheet.xsl-->

Running dir space test\sample1 sheet.xsl:
<p>Run with SAXON HE 12.4 at 2023-12-02T07:51:07.1600576+01:00; static-base-uri: file:///C:/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20te
st/sample1%20sheet.xsl</p><!--Run with SAXON HE 12.4 at 2023-12-02T07:51:07.1600576+01:00; static-base-uri: file:///C:/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20test/sample1%20sheet.xsl-->

Running dir space test/sample1 sheet.xsl:
<p>Run with SAXON HE 12.4 at 2023-12-02T07:51:07.1600576+01:00; static-base-uri: file:///C:/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20te
st/sample1%20sheet.xsl</p><!--Run with SAXON HE 12.4 at 2023-12-02T07:51:07.1600576+01:00; static-base-uri: file:///C:/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20test/sample1%20sheet.xsl-->

Running sample1 sheet.xsl:
<p>Run with SAXON HE 12.4 at 2023-12-02T07:51:07.1600576+01:00; static-base-uri: file:///C:/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/sample1%20sheet.
xsl</p><!--Run with SAXON HE 12.4 at 2023-12-02T07:51:07.1600576+01:00; static-base-uri: file:///C:/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/sample1%20sheet.xsl-->

Running dir space test/sample1 sheet.xsl:
<p>Run with SAXON HE 12.4 at 2023-12-02T07:51:07.1600576+01:00; static-base-uri: file:///C:/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20te
st/sample1%20sheet.xsl</p><!--Run with SAXON HE 12.4 at 2023-12-02T07:51:07.1600576+01:00; static-base-uri: file:///C:/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20test/sample1%20sheet.xsl-->

Running dir space test/sample1 sheet.xsl:
<p>Run with SAXON HE 12.4 at 2023-12-02T07:51:07.1600576+01:00; static-base-uri: file:///C:/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20te
st/sample1%20sheet.xsl</p><!--Run with SAXON HE 12.4 at 2023-12-02T07:51:07.1600576+01:00; static-base-uri: file:///C:/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20test/sample1%20sheet.xsl-->

Linux output:

(saxonche1241) mh@LIBERTYDELL23:/mnt/c/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces$ python main.py
SaxonC-HE 12.4 from Saxonica
Running sample1 sheet.xsl:
<p>Run with SAXON HE 12.4 at 2023-12-02T07:52:37.7209+01:00; static-base-uri: file:///mnt/c/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/sample1%20sheet.xsl</p><!--Run with SAXON HE 12.4 at 2023-12-02T07:52:37.7209+01:00; static-base-uri: file:///mnt/c/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/sample1%20sheet.xsl-->

Running dir space test\sample1 sheet.xsl:
<p>Run with SAXON HE 12.4 at 2023-12-02T07:52:37.740001+01:00; static-base-uri: file:///mnt/c/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20test/sample1%20sheet.xsl</p><!--Run with SAXON HE 12.4 at 2023-12-02T07:52:37.740001+01:00; static-base-uri: file:///mnt/c/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20test/sample1%20sheet.xsl-->

Running dir space test/sample1 sheet.xsl:
<p>Run with SAXON HE 12.4 at 2023-12-02T07:52:37.758782+01:00; static-base-uri: file:///mnt/c/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20test/sample1%20sheet.xsl</p><!--Run with SAXON HE 12.4 at 2023-12-02T07:52:37.758782+01:00; static-base-uri: file:///mnt/c/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20test/sample1%20sheet.xsl-->

Running sample1 sheet.xsl:
<p>Run with SAXON HE 12.4 at 2023-12-02T07:52:37.772325+01:00; static-base-uri: file:///mnt/c/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/sample1%20sheet.xsl</p><!--Run with SAXON HE 12.4 at 2023-12-02T07:52:37.772325+01:00; static-base-uri: file:///mnt/c/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/sample1%20sheet.xsl-->

Running dir space test\sample1 sheet.xsl:
<p>Run with SAXON HE 12.4 at 2023-12-02T07:52:37.790236+01:00; static-base-uri: file:///mnt/c/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20test/sample1%20sheet.xsl</p><!--Run with SAXON HE 12.4 at 2023-12-02T07:52:37.790236+01:00; static-base-uri: file:///mnt/c/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20test/sample1%20sheet.xsl-->

Running dir space test/sample1 sheet.xsl:
<p>Run with SAXON HE 12.4 at 2023-12-02T07:52:37.807477+01:00; static-base-uri: file:///mnt/c/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20test/sample1%20sheet.xsl</p><!--Run with SAXON HE 12.4 at 2023-12-02T07:52:37.807477+01:00; static-base-uri: file:///mnt/c/Users/marti/PycharmProjects/SaxonCHE124FilePathWithSpaces/dir%20space%20test/sample1%20sheet.xsl-->

XSLT:

<?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:output method="html" indent="yes" html-version="5"/>

  <xsl:template match="/" name="xsl:initial-template">
      <p>Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} at {current-dateTime()}; static-base-uri: {static-base-uri()}</p>
      <xsl:comment>Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} at {current-dateTime()}; static-base-uri: {static-base-uri()}</xsl:comment>
  </xsl:template>

</xsl:stylesheet>
Actions #2

Updated by Matt Patterson 3 months ago

  • Category set to C++ API
  • Status changed from New to In Progress
  • Assignee set to Matt Patterson

It looks like we're always escaping the file path/uri input, so becomes %20, but if a URI is supplied with escaping already performed, %20 becomes %2520. In 12.3 we weren't escaping the URI at all, which is why in 12.3 file:///C:/Users/Dan Haley/Desktop/try_saxon/ident.xsl doesn't work. The correct behaviour is for us to pass through fully-qualified URIs (so file://* and http://*), which we will presume are already correctly escaped, and escape everything else. This is a little trickier than it sounds, but totally doable. Thanks for reporting!

Actions #3

Updated by Matt Patterson about 1 month ago

  • Status changed from In Progress to Resolved
  • Fixed in version set to 12.4.2

This is now fixed, and the fix will be released with the next maintenance release, which should be very soon.

Actions #4

Updated by O'Neil Delpratt about 1 month ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100

Fix applied in SaxonC 12.4.2 maintenance release

Please register to edit this issue

Also available in: Atom PDF