@@ -30,10 +30,14 @@ class SemanticVersion with CompareMixin<SemanticVersion> {
30
30
// 2.15.0-233.0.dev (dev) (Mon Oct 18 14:06:26 2021 -0700) on "ios_x64"
31
31
// 2.15.0-178.1.beta
32
32
// 2.6.0-12.0.pre.443
33
+ // 2.6.0-12.0.pre-443
33
34
//
34
- // So split on the spaces to the version, and then on the dash char to
35
+ // First canonicalize the version string to convert any prerelease suffix
36
+ // with a "-" to a prerelease suffix with a ".".
37
+ final canonicalized = _canonicalizeVersion (versionString);
38
+ // Then split on the spaces to the version, and then on the dash char to
35
39
// separate the main semantic version from the pre release version.
36
- final splitOnSpaces = versionString .split (' ' );
40
+ final splitOnSpaces = canonicalized .split (' ' );
37
41
final version = splitOnSpaces.first;
38
42
final splitOnDash = version.split ('-' );
39
43
assert (splitOnDash.length <= 2 , 'version: $version ' );
@@ -115,6 +119,16 @@ class SemanticVersion with CompareMixin<SemanticVersion> {
115
119
116
120
int ? preReleaseMinor;
117
121
122
+ static final _nonStandardPreReleaseVersionRegex = RegExp (r'(\.pre)-(\d+)$' );
123
+
124
+ /// Canonicalizes a [semanticVersion] with a prerelease version suffix to use
125
+ /// a "." instead of a "-".
126
+ ///
127
+ /// e.g. 2.6.0-12.0.pre-443 -> 2.6.0-12.0.pre.443
128
+ static String _canonicalizeVersion (String semanticVersion) =>
129
+ semanticVersion.replaceFirstMapped (_nonStandardPreReleaseVersionRegex,
130
+ (match) => '${match [1 ]}.${match [2 ]}' );
131
+
118
132
bool get isPreRelease => preReleaseMajor != null || preReleaseMinor != null ;
119
133
120
134
bool isSupported ({required SemanticVersion minSupportedVersion}) =>
0 commit comments