Skip to content

Commit 143f4ca

Browse files
Fix pana fails with custom PUB_HOSTED_URL containing a path (#1522)
1 parent 67a09dc commit 143f4ca

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/src/utils.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,17 @@ Future<void> copyDir(String from, String to) async {
164164
}
165165

166166
Future<String> getVersionListing(String package, {Uri? pubHostedUrl}) async {
167-
final url = (pubHostedUrl ?? Uri.parse('https://pub.dartlang.org')).resolve(
168-
'/api/packages/$package',
169-
);
167+
var url = (pubHostedUrl ?? Uri.parse('https://pub.dartlang.org'))
168+
.normalizePath();
169+
// If we have a path of only '/'
170+
if (url.path == '/') {
171+
url = url.replace(path: '');
172+
}
173+
// If there is a path, and it doesn't end in a slash we normalize to slash
174+
if (url.path.isNotEmpty && !url.path.endsWith('/')) {
175+
url = url.replace(path: '${url.path}/');
176+
}
177+
url = url.resolve('api/packages/$package');
170178
log.fine('Downloading: $url');
171179

172180
return await retry(

0 commit comments

Comments
 (0)