Closed nerk closed 5 years ago
Actually this is a bug in Opal: https://github.com/opal/opal/pull/1601 This fix should be available in Opal 0.11 (not yet released)
I think this is also related to https://github.com/asciidoctor/asciidoctor/pull/1898, which is coming in 1.5.6.
I would say this is a bug in Opal...possibly still a bug.
The problem is, the File.expand_path implementation in Opal is not correctly expanding a Windows root. This method is used to resolve the value of the base_dir option.
Here's how it works in Ruby:
File.expand_path 'C:'
#=> C:/Users/Username/directory
File.expand_path 'C:/'
#=> C:/
File.expand_path 'D:'
#=> D:/
File.expand_path 'D:/'
#=> D:/
In other words, Ruby always leaves behind at least one slash in the path. And the PathResolver in Asciidoctor assumes this.
In contrast, here's what happens in Opal.
File.expand_path 'C:'
#=> C:/Users/Username/directory/C:
File.expand_path 'C:/'
#=> C:
File.expand_path 'D:'
#=> C:/Users/Username/directory/D:
File.expand_path 'D:/'
#=> D:
So Opal returns the correct result in 0% of the cases :wink:
We have to assume some level of consistency in Asciidoctor, and I'm going to assume the return value of File.expand_path is compliant. Specifically, it must contain at least one slash (and, bonus, it should also recognize a bare drive letter).
Having said that, there's an open question about whether the Asciidoctor PathResolver should recognize C:
(without the slash) as a Windows root. If we do that, we also need to change some assumptions in PathResolver#partition_path.
I just tested against Opal master and now all 4 cases returns the drive letter without the trailing slash. I'll report this upstream.
Correction: when using the nodejs module, all the results are still the same as initially reported.
See https://github.com/opal/opal/issues/1794
I'm still debating whether we should handle a bare drive letter (no trailing slash). I kind of want to say no, but it also seems a little fragile not to. :thinking:
This should be scheduled for 1.5.7 instead of 1.5.6.
A workaround you'll be able to use is to set the docdir
attribute, which does not get expanded. But you will need to include the trailing slash.
asciidoctorjs -a docdir=C:/ test.ad
When explicitly setting the 'base_dir' option, include blocks with absolute paths are no longer working. Asciidoctor.js does not seem to check if a path is absolute or relative.
Ruby Asciidoctor is working, though.
test.ad:
Testing from the command line:
Using Ruby Asciidoctor works: