From b05e8522b502b5825e309fe66a31035f65c70010 Mon Sep 17 00:00:00 2001 From: andreaTP Date: Wed, 30 Mar 2022 13:07:11 +0100 Subject: [PATCH] Fix Banner check on filesystem containing special chars --- .../deployment/steps/BannerProcessor.java | 11 +++--- .../pkg/steps/BannerProcessorTest.java | 32 ++++++++++++++++++ .../Desc\304\203rc\304\203ri/with-class.jar" | Bin 0 -> 300 bytes .../without-class.jar" | Bin 0 -> 168 bytes 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 core/deployment/src/test/java/io/quarkus/deployment/pkg/steps/BannerProcessorTest.java create mode 100644 "core/deployment/src/test/resources/test/Desc\304\203rc\304\203ri/with-class.jar" create mode 100644 "core/deployment/src/test/resources/test/Desc\304\203rc\304\203ri/without-class.jar" diff --git a/core/deployment/src/main/java/io/quarkus/deployment/steps/BannerProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/steps/BannerProcessor.java index c30633dccaed2..0b6c800271d9c 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/steps/BannerProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/steps/BannerProcessor.java @@ -1,12 +1,11 @@ package io.quarkus.deployment.steps; +import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; -import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.nio.file.Paths; +import java.nio.file.NoSuchFileException; import java.util.AbstractMap; import java.util.Enumeration; import java.util.Map; @@ -103,7 +102,7 @@ private Map.Entry getBanner(BannerConfig config) throws IOExceptio } } - private boolean isQuarkusCoreBanner(URL url) throws IOException { + protected boolean isQuarkusCoreBanner(URL url) throws IOException { if (!"jar".equals(url.getProtocol())) { return false; } @@ -114,9 +113,9 @@ private boolean isQuarkusCoreBanner(URL url) throws IOException { // We determine whether the banner is the default by checking to see if the jar that contains it also // contains this class. This way although somewhat complicated guarantees that any rename of artifacts // won't affect the check - try (JarFile jarFile = new JarFile(Paths.get(new URI(jarPath)).toFile())) { + try (JarFile jarFile = new JarFile(new File(jarPath))) { return jarFile.getJarEntry(thisClassName.replace('.', '/') + ".class") != null; - } catch (URISyntaxException e) { + } catch (NoSuchFileException e) { return false; } } diff --git a/core/deployment/src/test/java/io/quarkus/deployment/pkg/steps/BannerProcessorTest.java b/core/deployment/src/test/java/io/quarkus/deployment/pkg/steps/BannerProcessorTest.java new file mode 100644 index 0000000000000..8b8234d1368ff --- /dev/null +++ b/core/deployment/src/test/java/io/quarkus/deployment/pkg/steps/BannerProcessorTest.java @@ -0,0 +1,32 @@ +package io.quarkus.deployment.pkg.steps; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.net.URL; +import java.nio.file.Paths; + +import org.assertj.core.util.Files; +import org.junit.jupiter.api.Test; + +import io.quarkus.deployment.steps.BannerProcessor; + +public class BannerProcessorTest { + + class MyBannerProcessor extends BannerProcessor { + public boolean test(String file) throws Exception { + return this.isQuarkusCoreBanner(new URL("jar", null, 0, file)); + } + } + + @Test + public void checkQuarkusCoreBannerOnFilesystemWithSpecialCharacters() throws Exception { + MyBannerProcessor processor = new MyBannerProcessor(); + + assertFalse(processor.test(Paths.get("tmp", "Descărcări", "test", "something!").toFile().getAbsolutePath())); + assertFalse(processor.test(Paths.get(Files.currentFolder().getAbsolutePath(), "src", "test", "resources", "test", + "Descărcări", "without-class.jar!").toFile().getAbsolutePath())); + assertTrue(processor.test(Paths.get(Files.currentFolder().getAbsolutePath(), "src", "test", "resources", "test", + "Descărcări", "with-class.jar!").toFile().getAbsolutePath())); + } +} diff --git "a/core/deployment/src/test/resources/test/Desc\304\203rc\304\203ri/with-class.jar" "b/core/deployment/src/test/resources/test/Desc\304\203rc\304\203ri/with-class.jar" new file mode 100644 index 0000000000000000000000000000000000000000..7cc7355144239a01e91127d396b00bc05edd6fee GIT binary patch literal 300 zcmWIWW@h1H0D<#qbs=B|l<;PdVaUwaFDy+g$}TO|Pf0Dv$*;^!%`4F_$WGTUE=esY z)^|$G%S$Z^D9TSxEiTS43P~+4QSq%r6V*%3Nh~f74dG;9{_5hA1j3~i+zgB?Ul|z~ uSVVx<1$Z+u$uZ+{h6LPIOBz8;syd1l;wTIUv9f`zVg$m8K)MygVE_R4zE3~^ literal 0 HcmV?d00001 diff --git "a/core/deployment/src/test/resources/test/Desc\304\203rc\304\203ri/without-class.jar" "b/core/deployment/src/test/resources/test/Desc\304\203rc\304\203ri/without-class.jar" new file mode 100644 index 0000000000000000000000000000000000000000..df010a065473c60139e0687ab87724d68cd36e37 GIT binary patch literal 168 zcmWIWW@h1H0D(WLbs=B|l;C8LVMxs_D5*@#%t;Lm;bdUWadt@p;nE6j21b^zj0_Ac rB0$9f-i%Cg%(x7ZfSb9b5yV6?k`-bkhH