Skip to content

Commit

Permalink
Fix for resolving absolute paths when base is within JAR
Browse files Browse the repository at this point in the history
  • Loading branch information
bertfrees committed Mar 30, 2017
1 parent 7a7e75c commit ccb40e6
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/main/java/com/xmlcalabash/util/XProcURIResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,25 +211,30 @@ public XdmNode parse(String href, String base, boolean dtdValidate) {

if (source == null) {
try {
URI baseURI = new URI(base);
URI resURI = baseURI.resolve(href);

String path = baseURI.toASCIIString();
int pos = path.indexOf("!");
if (pos > 0 && (path.startsWith("jar:file:") || path.startsWith("jar:http:") || path.startsWith("jar:https:"))) {
// You can't resolve() against jar: scheme URIs because they appear to be opaque.
// I wonder if what follows is kosher...
String fakeURIstr = "http://example.com";
String subpath = path.substring(pos+1);
if (subpath.startsWith("/")) {
fakeURIstr += subpath;
} else {
fakeURIstr += "/" + subpath;
URI resURI; {
resURI = new URI(href);
if (!resURI.isAbsolute()) {
URI baseURI = new URI(base);
String path = baseURI.toASCIIString();
int pos = path.indexOf("!");
if (pos > 0 && (path.startsWith("jar:file:") || path.startsWith("jar:http:") || path.startsWith("jar:https:"))) {
// You can't resolve() against jar: scheme URIs because they appear to be opaque.
// I wonder if what follows is kosher...
String fakeURIstr = "http://example.com";
String subpath = path.substring(pos+1);
if (subpath.startsWith("/")) {
fakeURIstr += subpath;
} else {
fakeURIstr += "/" + subpath;
}
URI fakeURI = new URI(fakeURIstr);
resURI = fakeURI.resolve(href);
fakeURIstr = path.substring(0,pos+1) + resURI.getPath();
resURI = new URI(fakeURIstr);
} else {
resURI = baseURI.resolve(href);
}
}
URI fakeURI = new URI(fakeURIstr);
resURI = fakeURI.resolve(href);
fakeURIstr = path.substring(0,pos+1) + resURI.getPath();
resURI = new URI(fakeURIstr);
}

source = new SAXSource(new InputSource(resURI.toASCIIString()));
Expand Down

0 comments on commit ccb40e6

Please sign in to comment.