Skip to content

Commit

Permalink
fix(model): Correctly en- / decode a VCS subpath to / from PURLs
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Jan 11, 2024
1 parent 42bf356 commit 19553b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions model/src/main/kotlin/utils/PurlExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fun KnownProvenance.toPurlExtras(): PurlExtras =
fun String.toProvenance(): Provenance {
val extras = substringAfter('?')

fun getQualifierValue(name: String) = extras.substringAfter("$name=").substringBefore('&')
fun getQualifierValue(name: String) = extras.substringAfter("$name=").takeWhile { it != '&' && it != '#' }

return when {
"download_url=" in extras -> {
Expand All @@ -132,7 +132,8 @@ fun String.toProvenance(): Provenance {
vcsInfo = VcsInfo(
type = VcsType.forName(getQualifierValue("vcs_type")),
url = URLDecoder.decode(encodedUrl, "UTF-8"),
revision = getQualifierValue("vcs_revision")
revision = getQualifierValue("vcs_revision"),
path = extras.substringAfterLast('#', "")
),
resolvedRevision = getQualifierValue("resolved_revision")
)
Expand Down
6 changes: 4 additions & 2 deletions model/src/test/kotlin/utils/PurlExtensionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class PurlExtensionsTest : StringSpec({
vcsInfo = VcsInfo(
type = VcsType.GIT,
url = "https://github.com/apache/commons-text.git",
revision = "7643b12421100d29fd2b78053e77bcb04a251b2e"
revision = "7643b12421100d29fd2b78053e77bcb04a251b2e",
path = "subpath"
),
resolvedRevision = "7643b12421100d29fd2b78053e77bcb04a251b2e"
)
Expand All @@ -72,7 +73,8 @@ class PurlExtensionsTest : StringSpec({
"vcs_type=Git&" +
"vcs_url=https%3A%2F%2Fgithub.com%2Fapache%2Fcommons-text.git&" +
"vcs_revision=7643b12421100d29fd2b78053e77bcb04a251b2e&" +
"resolved_revision=7643b12421100d29fd2b78053e77bcb04a251b2e"
"resolved_revision=7643b12421100d29fd2b78053e77bcb04a251b2e" +
"#subpath"
purl.toProvenance() shouldBe provenance
}

Expand Down

0 comments on commit 19553b6

Please sign in to comment.