djc / rnc2rng

RELAX NG Compact to regular syntax conversion library
MIT License
16 stars 13 forks source link

Parsing fails on Windows when filename is not relative path in current working dir #31

Closed rly closed 3 years ago

rly commented 3 years ago
  1. On Windows, the following:
    import rnc2rng
    rnc2rng.load('citeproc/data/schema/csl.rnc')

    results in error: [Errno 2] No such file or directory: 'csl-terms.rnc'

This appears to be due to changes in #18, specifically: https://github.com/djc/rnc2rng/blob/d5405e85f8889ed54d13bfc494e81b7ffd337103/rnc2rng/parser.py#L215-L220

s.path is set to the directory name of the input filename. Windows paths include a ":", so line 216 treats the path as a URL and calls urljoin on the path. This fails to join a Windows directory name with a filename. Execution should instead enter the else statement.

  1. On Windows, the following:
    import rnc2rng
    rnc2rng.load('C:/Users/Ryan/Documents/citeproc-py/citeproc/data/schema/csl.rnc')

    fails with urllib.error.URLError: <urlopen error unknown url type: c>.

Again, this is because absolute paths on Windows contain a ":" and this line: https://github.com/djc/rnc2rng/blob/d5405e85f8889ed54d13bfc494e81b7ffd337103/rnc2rng/parser.py#L693

treats the path as a url. Execution should instead enter the else statement.

djc commented 3 years ago

Sounds like you got a handle on this! Could you do a PR?