From 2145bdbf4c954dfa54c3d316ad99dd014a2f46fd Mon Sep 17 00:00:00 2001 From: memo Date: Thu, 19 Dec 2024 10:32:55 +0100 Subject: [PATCH] fix encoding of spaces in metadata source URL Resolves https://github.com/memo33/sc4pac/issues/58 --- CHANGELOG.md | 2 ++ src/main/scala/sc4pac/ChannelUtil.scala | 5 ++++- src/test/scala/sc4pac/ChannelSpec.scala | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cb2658..24aefca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ## [Unreleased] +### Fixed +- an issue where building a channel with file names containing spaces failed ## [0.5.0] - 2024-12-14 diff --git a/src/main/scala/sc4pac/ChannelUtil.scala b/src/main/scala/sc4pac/ChannelUtil.scala index eeb1917..eb9ab95 100644 --- a/src/main/scala/sc4pac/ChannelUtil.scala +++ b/src/main/scala/sc4pac/ChannelUtil.scala @@ -25,6 +25,9 @@ object ChannelUtil { ) } + private[sc4pac] def resolveMetadataSourceUrl(baseUri: java.net.URI, path: os.SubPath): java.net.URI = + baseUri.resolve(os.root.toNIO.toUri.relativize((os.root / path).toNIO.toUri)) + case class YamlPackageData( group: String, name: String, @@ -50,7 +53,7 @@ object ChannelUtil { for { baseUri <- channelInfo.metadataSourceUrl path <- metadataSource - } yield baseUri.resolve(path.segments0.mkString("/")), + } yield resolveMetadataSourceUrl(baseUri, path), channelLabel = channelInfo.channelLabel, )} } diff --git a/src/test/scala/sc4pac/ChannelSpec.scala b/src/test/scala/sc4pac/ChannelSpec.scala index 71def04..06b0274 100644 --- a/src/test/scala/sc4pac/ChannelSpec.scala +++ b/src/test/scala/sc4pac/ChannelSpec.scala @@ -124,6 +124,12 @@ url: dummy ).head._2 .map(_.orgName).toSet.shouldBe(Set("test:pkg1", "test:pkg2")) } + + "encode spaces in metadata source URL" in { + val baseUri = java.net.URI("https://github.com/memo33/sc4pac/blob/main/src/yaml/") + ChannelUtil.resolveMetadataSourceUrl(baseUri, os.SubPath("a b/c d.yaml")) + .toString.shouldBe(s"${baseUri}a%20b/c%20d.yaml") + } } }