Merge branch '1.5.x'

pull/12574/merge
Phillip Webb 7 years ago
commit 696aedaef8

@ -257,10 +257,10 @@ final class JarURLConnection extends java.net.JarURLConnection {
int index = indexOfRootSpec(spec, jarFile.getPathFromRoot()); int index = indexOfRootSpec(spec, jarFile.getPathFromRoot());
int separator; int separator;
while ((separator = spec.indexOf(SEPARATOR, index)) > 0) { while ((separator = spec.indexOf(SEPARATOR, index)) > 0) {
StringSequence entryName = spec.subSequence(index, separator); JarEntryName entryName = JarEntryName.get(spec.subSequence(index, separator));
JarEntry jarEntry = jarFile.getJarEntry(entryName); JarEntry jarEntry = jarFile.getJarEntry(entryName.toCharSequence());
if (jarEntry == null) { if (jarEntry == null) {
return JarURLConnection.notFound(jarFile, JarEntryName.get(entryName)); return JarURLConnection.notFound(jarFile, entryName);
} }
jarFile = jarFile.getNestedJarFile(jarEntry); jarFile = jarFile.getNestedJarFile(jarEntry);
index = separator + SEPARATOR.length(); index = separator + SEPARATOR.length();
@ -360,6 +360,10 @@ final class JarURLConnection extends java.net.JarURLConnection {
return ((char) ((hi << 4) + lo)); return ((char) ((hi << 4) + lo));
} }
public CharSequence toCharSequence() {
return this.name;
}
@Override @Override
public String toString() { public String toString() {
return this.name.toString(); return this.name.toString();

@ -51,6 +51,7 @@ public abstract class TestJarCreator {
writeNestedEntry("nested.jar", unpackNested, jarOutputStream); writeNestedEntry("nested.jar", unpackNested, jarOutputStream);
writeNestedEntry("another-nested.jar", unpackNested, jarOutputStream); writeNestedEntry("another-nested.jar", unpackNested, jarOutputStream);
writeNestedEntry("space nested.jar", unpackNested, jarOutputStream);
} }
} }

@ -108,7 +108,7 @@ public class ExplodedArchiveTests {
@Test @Test
public void getEntries() { public void getEntries() {
Map<String, Archive.Entry> entries = getEntriesMap(this.archive); Map<String, Archive.Entry> entries = getEntriesMap(this.archive);
assertThat(entries.size()).isEqualTo(10); assertThat(entries.size()).isEqualTo(11);
} }
@Test @Test

@ -82,7 +82,7 @@ public class JarFileArchiveTests {
@Test @Test
public void getEntries() { public void getEntries() {
Map<String, Archive.Entry> entries = getEntriesMap(this.archive); Map<String, Archive.Entry> entries = getEntriesMap(this.archive);
assertThat(entries.size()).isEqualTo(10); assertThat(entries.size()).isEqualTo(11);
} }
@Test @Test

@ -81,6 +81,7 @@ public class CentralDirectoryParserTests {
assertThat(headers.next().getName().toString()).isEqualTo("special/\u00EB.dat"); assertThat(headers.next().getName().toString()).isEqualTo("special/\u00EB.dat");
assertThat(headers.next().getName().toString()).isEqualTo("nested.jar"); assertThat(headers.next().getName().toString()).isEqualTo("nested.jar");
assertThat(headers.next().getName().toString()).isEqualTo("another-nested.jar"); assertThat(headers.next().getName().toString()).isEqualTo("another-nested.jar");
assertThat(headers.next().getName().toString()).isEqualTo("space nested.jar");
assertThat(headers.hasNext()).isFalse(); assertThat(headers.hasNext()).isFalse();
} }

@ -93,6 +93,7 @@ public class JarFileTests {
assertThat(entries.nextElement().getName()).isEqualTo("special/\u00EB.dat"); assertThat(entries.nextElement().getName()).isEqualTo("special/\u00EB.dat");
assertThat(entries.nextElement().getName()).isEqualTo("nested.jar"); assertThat(entries.nextElement().getName()).isEqualTo("nested.jar");
assertThat(entries.nextElement().getName()).isEqualTo("another-nested.jar"); assertThat(entries.nextElement().getName()).isEqualTo("another-nested.jar");
assertThat(entries.nextElement().getName()).isEqualTo("space nested.jar");
assertThat(entries.hasMoreElements()).isFalse(); assertThat(entries.hasMoreElements()).isFalse();
URL jarUrl = new URL("jar:" + this.rootJarFile.toURI() + "!/"); URL jarUrl = new URL("jar:" + this.rootJarFile.toURI() + "!/");
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { jarUrl }); URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { jarUrl });
@ -135,6 +136,7 @@ public class JarFileTests {
assertThat(entries.nextElement().getName()).isEqualTo("special/\u00EB.dat"); assertThat(entries.nextElement().getName()).isEqualTo("special/\u00EB.dat");
assertThat(entries.nextElement().getName()).isEqualTo("nested.jar"); assertThat(entries.nextElement().getName()).isEqualTo("nested.jar");
assertThat(entries.nextElement().getName()).isEqualTo("another-nested.jar"); assertThat(entries.nextElement().getName()).isEqualTo("another-nested.jar");
assertThat(entries.nextElement().getName()).isEqualTo("space nested.jar");
assertThat(entries.hasMoreElements()).isFalse(); assertThat(entries.hasMoreElements()).isFalse();
} }

@ -134,6 +134,21 @@ public class JarURLConnectionTests {
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 })); .hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
} }
@Test
public void connectionToEntryWithSpaceNestedEntry() throws Exception {
URL url = new URL("jar:file:" + getRelativePath() + "!/space nested.jar!/3.dat");
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
}
@Test
public void connectionToEntryWithEncodedSpaceNestedEntry() throws Exception {
URL url = new URL(
"jar:file:" + getRelativePath() + "!/space%20nested.jar!/3.dat");
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
}
@Test @Test
public void getContentLengthReturnsLengthOfUnderlyingEntry() throws Exception { public void getContentLengthReturnsLengthOfUnderlyingEntry() throws Exception {
URL url = new URL(new URL("jar", null, -1, URL url = new URL(new URL("jar", null, -1,

Loading…
Cancel
Save