diff --git a/plugins/package-managers/pub/src/main/kotlin/utils/PubCacheReader.kt b/plugins/package-managers/pub/src/main/kotlin/utils/PubCacheReader.kt index 2123f0e1d1c71..657b472470a48 100644 --- a/plugins/package-managers/pub/src/main/kotlin/utils/PubCacheReader.kt +++ b/plugins/package-managers/pub/src/main/kotlin/utils/PubCacheReader.kt @@ -85,13 +85,13 @@ internal class PubCacheReader(flutterHome: File? = null) { val path = if (type == "hosted" && url.isNotEmpty()) { // Packages with source set to "hosted" and "url" key in description set to "https://pub.dartlang.org". // The path should be resolved to "hosted/pub.dartlang.org/packageName-packageVersion". - "hosted/${url.replace("https://", "")}/$packageName-$packageVersion" + "hosted/${url.replace("https://", "").replace("/","%47")}/$packageName-$packageVersion" } else if (type == "git" && resolvedRef.isNotEmpty()) { // Packages with source set to "git" and a "resolved-ref" key in description set to a gitHash. // These packages do not define a packageName in the packageInfo, but by definition the path resolves to // the project name as given from the VcsHost and to the resolvedRef. val projectName = VcsHost.getProject(url) ?: return null - if (resolvedPath.isNotEmpty()) { + if (resolvedPath.isNotEmpty() && resolvedPath != ".") { "git/$projectName-$resolvedRef/$resolvedPath" } else { "git/$projectName-$resolvedRef" diff --git a/plugins/package-managers/pub/src/test/kotlin/utils/PubCacheReaderTest.kt b/plugins/package-managers/pub/src/test/kotlin/utils/PubCacheReaderTest.kt index c751589ec21c0..ffa1174481b41 100644 --- a/plugins/package-managers/pub/src/test/kotlin/utils/PubCacheReaderTest.kt +++ b/plugins/package-managers/pub/src/test/kotlin/utils/PubCacheReaderTest.kt @@ -40,6 +40,7 @@ class PubCacheReaderTest : WordSpec({ val gitPackageCacheDir = tmpPubCacheDir.resolve("git/$PACKAGE_NAME-$RESOLVED_REF") val gitPackageWithPathCacheDir = tmpPubCacheDir.resolve("git/$PACKAGE_NAME-$RESOLVED_REF/$PACKAGE_NAME") val hostedPackageCacheDir = tmpPubCacheDir.resolve("hosted/oss-review-toolkit.org/$PACKAGE_NAME-$PACKAGE_VERSION") + val customPackageCacheDir = tmpPubCacheDir.resolve("hosted/oss-review-toolkit.org%47api%47pub%47repository%47/$PACKAGE_NAME-$PACKAGE_VERSION") val localPackagePathAbsolute = ABSOLUTE_PATH val localPackagePathRelative = ABSOLUTE_PATH.resolve(RELATIVE_PATH) @@ -72,6 +73,27 @@ class PubCacheReaderTest : WordSpec({ ) shouldBe gitPackageCacheDir } + "resolve the path of a Git dependency with special path" { + reader.findProjectRoot( + jsonMapper.readTree( + """ + { + "dependency": "direct main", + "description": { + "path": ".", + "ref": "master", + "resolved-ref": "$RESOLVED_REF", + "url": "https://github.com/oss-review-toolkit/$PACKAGE_NAME.git" + }, + "source": "git", + "version": "9.9.9" + } + """.trimIndent() + ), + ABSOLUTE_PATH // not used + ) shouldBe gitPackageCacheDir + } + "resolve the path of a Git dependency with path" { reader.findProjectRoot( jsonMapper.readTree( @@ -93,7 +115,7 @@ class PubCacheReaderTest : WordSpec({ ) shouldBe gitPackageWithPathCacheDir } - "resolve the path of a hosted dependency" { + "resolve the path of a custom package repository dependency" { PubCacheReader().findProjectRoot( jsonMapper.readTree( """ @@ -101,7 +123,7 @@ class PubCacheReaderTest : WordSpec({ "dependency": "transitive", "description": { "name": "$PACKAGE_NAME", - "url": "https://oss-review-toolkit.org" + "url": "https://oss-review-toolkit.org/api/pub/repository/" }, "source": "hosted", "version": "$PACKAGE_VERSION" @@ -109,7 +131,7 @@ class PubCacheReaderTest : WordSpec({ """.trimIndent() ), ABSOLUTE_PATH // not used - ) shouldBe hostedPackageCacheDir + ) shouldBe customPackageCacheDir } "resolve the relative path of a local dependency" {