Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/core/extensions/harness/extension_manifest_validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ final _semver = RegExp(r'^\d+\.\d+\.\d+(?:[+-][0-9A-Za-z.+-]+)?$');
/// as `>=0.4.0 <3.0.0`: `>=x.y.z`, `>x.y.z`, `<=x.y.z`, `<x.y.z`, `=x.y.z`,
/// `^x.y.z` (same major, or the same minor while major is 0), or `*` alone.
bool? engineRangeAllows(HostVersion host, String range) {
final parts = range.trim().split(RegExp(r'\s+'));
// `>= 0.4.0` reads the same as `>=0.4.0`: glue an operator to its version.
final parts = range
.trim()
.replaceAllMapped(RegExp(r'(>=|<=|>|<|=|\^)\s+'), (m) => m[1]!)
.split(RegExp(r'\s+'));
if (parts.length == 1 && parts.single == '*') return true;
var allowed = true;
for (final part in parts) {
Expand All @@ -182,8 +186,8 @@ bool? engineRangeAllows(HostVersion host, String range) {
bool? _comparatorAllows(HostVersion host, String c) {
try {
if (c.startsWith('>=')) return host >= HostVersion.parse(c.substring(2));
if (c.startsWith('<=')) return !(HostVersion.parse(c.substring(2)) < host);
if (c.startsWith('>')) return !(host <= HostVersion.parse(c.substring(1)));
if (c.startsWith('<=')) return host <= HostVersion.parse(c.substring(2));
if (c.startsWith('>')) return host > HostVersion.parse(c.substring(1));
if (c.startsWith('<')) return host < HostVersion.parse(c.substring(1));
if (c.startsWith('=')) return host == HostVersion.parse(c.substring(1));
if (c.startsWith('^')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final class HostVersion implements Comparable<HostVersion> {
return patch.compareTo(other.patch);
}

bool operator >(HostVersion other) => compareTo(other) > 0;
bool operator >=(HostVersion other) => compareTo(other) >= 0;
bool operator <(HostVersion other) => compareTo(other) < 0;
bool operator <=(HostVersion other) => compareTo(other) <= 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ void main() {
expect(allows('0.5.0', ' >=0.4.0 <3.0.0 '), isTrue);
});

test('spaces between an operator and its version are tolerated (#1635)',
() {
const range = '>= 0.4.0 < 3.0.0';
expect(allows('0.4.19', range), isTrue);
expect(allows('3.0.0', range), isFalse);
expect(allows('0.3.0', range), isFalse);
expect(allows('0.4.1', '> 0.4.0'), isTrue);
expect(allows('0.4.0', '<= 0.4.0'), isTrue);
expect(allows('0.4.19', '= 0.4.19'), isTrue);
expect(allows('0.4.19', '^ 0.4.11'), isTrue);
expect(allows('0.5.0', '>='), isNull);
});

test('HostVersion has a > operator (#1636)', () {
expect(HostVersion.parse('0.4.1') > HostVersion.parse('0.4.0'), isTrue);
expect(HostVersion.parse('0.4.0') > HostVersion.parse('0.4.0'), isFalse);
expect(HostVersion.parse('0.3.9') > HostVersion.parse('0.4.0'), isFalse);
});

test('* means any version; a range it cannot read is null, not a guess', () {
expect(allows('0.5.0', '*'), isTrue);
for (final bad in ['~0.4', '>=0.4.0 || ^1.0.0', '>=x', '', '0.4.19', '* <3.0.0']) {
Expand Down
Loading