Skip to content

Commit

Permalink
Merge branch '1.5.x' into 2.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Aug 13, 2018
2 parents f4b0101 + 384cfd2 commit 29e38f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,15 @@ private String trimToJarRoot(String file) {
}

private void setFile(URL context, String file) {
setURL(context, JAR_PROTOCOL, null, -1, null, null, normalize(file), null, null);
String path = normalize(file);
String query = null;
int queryIndex = path.lastIndexOf('?');
if (queryIndex != -1) {
query = path.substring(queryIndex + 1);
path = path.substring(0, queryIndex);
}
setURL(context, JAR_PROTOCOL, null, -1, null, null, path, query,
context.getRef());
}

private String normalize(String file) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -158,12 +158,28 @@ public void urlWithSpecReferencingCurrentDirectory() throws MalformedURLExceptio
"./folderB/./b.xsd");
}

@Test
public void urlWithRef() throws MalformedURLException {
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes",
"!/foo.txt#alpha");
}

@Test
public void urlWithQuery() throws MalformedURLException {
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes",
"!/foo.txt?alpha");
}

private void assertStandardAndCustomHandlerUrlsAreEqual(String context, String spec)
throws MalformedURLException {
URL standardUrl = new URL(new URL("jar:" + context), spec);
URL customHandlerUrl = new URL(new URL("jar", null, -1, context, this.handler),
spec);
assertThat(customHandlerUrl.toString()).isEqualTo(standardUrl.toString());
assertThat(customHandlerUrl.getFile()).isEqualTo(standardUrl.getFile());
assertThat(customHandlerUrl.getPath()).isEqualTo(standardUrl.getPath());
assertThat(customHandlerUrl.getQuery()).isEqualTo(standardUrl.getQuery());
assertThat(customHandlerUrl.getRef()).isEqualTo(standardUrl.getRef());
}

private URL createUrl(String file) throws MalformedURLException {
Expand Down

0 comments on commit 29e38f4

Please sign in to comment.