Skip to content

Commit

Permalink
Only allow pub.dev as Dart package repository
Browse files Browse the repository at this point in the history
Because arbitrary URLs can point to non-pub compatible websites
  • Loading branch information
z80maniac committed Jun 23, 2024
1 parent 546078e commit 942fb09
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/package_managers/pub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PubLockEntry extends LockEntry {
required this.pubUrl
});

final String pubUrl;
final String? pubUrl;
}

class PubPackage extends Package {
Expand Down Expand Up @@ -132,9 +132,11 @@ class Pub extends PackageManager {
var isDev = dependencyFlags.contains('dev');
var packageName = packageItem.key;
var packageMap = packageItem.value;
String pubUrl;
String? pubUrl;
try {
pubUrl = packageMap['description']['url'] as String;
if(pubUrl != 'https://pub.dev')
pubUrl = null;
} catch(e) {
Log.exception(e, 'Package $packageName${isDev ? ' (dev)' : ''}, fetching description URL');
continue;
Expand All @@ -149,7 +151,7 @@ class Pub extends PackageManager {

var lockMeta = LockEntryMeta(
version: version,
infoUrl: '$pubUrl/api/packages/$packageName'
infoUrl: pubUrl == null ? null : '$pubUrl/api/packages/$packageName'
);
var entry = PubLockEntry(
name: packageName,
Expand Down

0 comments on commit 942fb09

Please sign in to comment.