From da1f300ce5056559ec66a406b2216c0a7f2902ef Mon Sep 17 00:00:00 2001 From: Roman Langolf Date: Sun, 8 Dec 2024 13:40:27 +0700 Subject: [PATCH 1/2] add a workaround for double url encoded + in the resources path --- .../src/main/scala-3/dumbo/ResourceFilePath.scala | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/core/shared/src/main/scala-3/dumbo/ResourceFilePath.scala b/modules/core/shared/src/main/scala-3/dumbo/ResourceFilePath.scala index aa56f44..154c866 100644 --- a/modules/core/shared/src/main/scala-3/dumbo/ResourceFilePath.scala +++ b/modules/core/shared/src/main/scala-3/dumbo/ResourceFilePath.scala @@ -27,7 +27,20 @@ object ResourceFilePath: val srcUriStr = head.toURI().toString() val jarFilePath = srcUriStr.slice(srcUriStr.lastIndexOf(":") + 1, srcUriStr.lastIndexOf("!")) - val resources = scala.util.Using.resource(java.util.zip.ZipFile(jarFilePath)) { fs => + def openJar(path: String) = try { + java.util.zip.ZipFile(jarFilePath) + } catch { + case _: Throwable => + // another attempt as a (hopefully temporary) workaround in case a path got URL encoded twice + // e.g. a common SNAPSHOT version may contain a '+' sign and look like 'my-lib-0.0.0+123-456-SNAPSHOT' + // it seems to end up URL encoded on the file system (at least via coursier) and look like that "my-lib-0.0.0%2B123-456-SNAPSHOT.jar" + // on getting the URL via getResources() the path is URL encoded again and becomes: "my-lib-0.0.0%252B123-456-SNAPSHOT.jar" + // not sure yet which side would need to fix that, for now this gets it working + // helps only with a double encoded `+` sign which may be commonly used in snapshot versions + java.util.zip.ZipFile(jarFilePath.replace("%252B", "%2B")) + } + + val resources = scala.util.Using.resource(openJar(jarFilePath)) { fs => fs .entries() .asScala From 5c89faf2ce8c6a570e1c719dd3a8f680aa7aabad Mon Sep 17 00:00:00 2001 From: Roman Langolf Date: Sun, 8 Dec 2024 14:21:51 +0700 Subject: [PATCH 2/2] remove redundant method --- .../main/scala-3/dumbo/ResourceFilePath.scala | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/core/shared/src/main/scala-3/dumbo/ResourceFilePath.scala b/modules/core/shared/src/main/scala-3/dumbo/ResourceFilePath.scala index 154c866..20c5d38 100644 --- a/modules/core/shared/src/main/scala-3/dumbo/ResourceFilePath.scala +++ b/modules/core/shared/src/main/scala-3/dumbo/ResourceFilePath.scala @@ -27,20 +27,20 @@ object ResourceFilePath: val srcUriStr = head.toURI().toString() val jarFilePath = srcUriStr.slice(srcUriStr.lastIndexOf(":") + 1, srcUriStr.lastIndexOf("!")) - def openJar(path: String) = try { - java.util.zip.ZipFile(jarFilePath) - } catch { - case _: Throwable => - // another attempt as a (hopefully temporary) workaround in case a path got URL encoded twice - // e.g. a common SNAPSHOT version may contain a '+' sign and look like 'my-lib-0.0.0+123-456-SNAPSHOT' - // it seems to end up URL encoded on the file system (at least via coursier) and look like that "my-lib-0.0.0%2B123-456-SNAPSHOT.jar" - // on getting the URL via getResources() the path is URL encoded again and becomes: "my-lib-0.0.0%252B123-456-SNAPSHOT.jar" - // not sure yet which side would need to fix that, for now this gets it working - // helps only with a double encoded `+` sign which may be commonly used in snapshot versions - java.util.zip.ZipFile(jarFilePath.replace("%252B", "%2B")) - } - - val resources = scala.util.Using.resource(openJar(jarFilePath)) { fs => + val resources = scala.util.Using.resource { + try { + java.util.zip.ZipFile(jarFilePath) + } catch { + case _: Throwable => + // another attempt as a (hopefully temporary) workaround in case a path got URL encoded twice + // e.g. a common SNAPSHOT version may contain a '+' sign and look like 'my-lib-0.0.0+123-456-SNAPSHOT' + // it seems to end up URL encoded on the file system (at least via coursier) and look like that "my-lib-0.0.0%2B123-456-SNAPSHOT.jar" + // on getting the URL via getResources() the path is URL encoded again and becomes: "my-lib-0.0.0%252B123-456-SNAPSHOT.jar" + // not sure yet which side would need to fix that, for now this gets it working + // helps only with a double encoded `+` sign which may be commonly used in snapshot versions + java.util.zip.ZipFile(jarFilePath.replace("%252B", "%2B")) + } + } { fs => fs .entries() .asScala