I always thought that URL
s can be composed via this constructor, and with something like
new URL(new URL("file:/foo/bar/"), "images/a.png")
I get
file:/foo/bar/images/a.png
as expected.1 However, from OneJar I obtain a strange looking URL and the result of
new URL(new URL("onejar:foo.bar"), "images.a.png")
is simply
onejar:images.a.png
The parent path gets simply dropped. I tried to prefix or suffix the parts with /
or .
, but nothing changes. Update: This isn't true, see below.
Is this a bug or am I missing something? Do I have to do it via strings (which feels pretty hacky).
UPDATE:
I see that the trailing slash indeed helps. For whatever reason, onejar
uses dots as delimiters, but it seems to accept slashes as well. So I can take the original URL like onejar:foo.bar
convert to a string, append /
, and convert back to URL. The result can be then composed via the constructor mentioned above, so it seems to be the right way.
1 unless I forget the trailing slash, which I do very often, but this is a different story.