Merge pull request #10706 from Ali Kord
* gh-10706: Polish "Fix handling of spaces in container's document root" Fix handling of spaces in container's document root
This commit is contained in:
commit
3cc7509804
|
|
@ -194,23 +194,29 @@ public abstract class AbstractEmbeddedServletContainerFactory
|
|||
}
|
||||
|
||||
private File getCodeSourceArchive() {
|
||||
return getCodeSourceArchive(getClass().getProtectionDomain().getCodeSource());
|
||||
}
|
||||
|
||||
File getCodeSourceArchive(CodeSource codeSource) {
|
||||
try {
|
||||
CodeSource codeSource = getClass().getProtectionDomain().getCodeSource();
|
||||
URL location = (codeSource == null ? null : codeSource.getLocation());
|
||||
if (location == null) {
|
||||
return null;
|
||||
}
|
||||
String path = location.getPath();
|
||||
String path;
|
||||
URLConnection connection = location.openConnection();
|
||||
if (connection instanceof JarURLConnection) {
|
||||
path = ((JarURLConnection) connection).getJarFile().getName();
|
||||
}
|
||||
if (path.indexOf("!/") != -1) {
|
||||
else {
|
||||
path = location.toURI().getPath();
|
||||
}
|
||||
if (path.contains("!/")) {
|
||||
path = path.substring(0, path.indexOf("!/"));
|
||||
}
|
||||
return new File(path);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,9 +30,11 @@ import java.net.URI;
|
|||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.CodeSource;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -673,6 +675,24 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
|||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void codeSourceArchivePath() throws Exception {
|
||||
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
||||
CodeSource codeSource = new CodeSource(new URL("file", "", "/some/test/path/"),
|
||||
(Certificate[]) null);
|
||||
File codeSourceArchive = factory.getCodeSourceArchive(codeSource);
|
||||
assertThat(codeSourceArchive).isEqualTo(new File("/some/test/path/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void codeSourceArchivePathContainingSpaces() throws Exception {
|
||||
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
||||
CodeSource codeSource = new CodeSource(
|
||||
new URL("file", "", "/test/path/with%20space/"), (Certificate[]) null);
|
||||
File codeSourceArchive = factory.getCodeSourceArchive(codeSource);
|
||||
assertThat(codeSourceArchive).isEqualTo(new File("/test/path/with space/"));
|
||||
}
|
||||
|
||||
protected Ssl getSsl(ClientAuth clientAuth, String keyPassword, String keyStore) {
|
||||
return getSsl(clientAuth, keyPassword, keyStore, null, null, null);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue