@@ -30,10 +30,14 @@ class SemanticVersion with CompareMixin<SemanticVersion> {
3030 // 2.15.0-233.0.dev (dev) (Mon Oct 18 14:06:26 2021 -0700) on "ios_x64"
3131 // 2.15.0-178.1.beta
3232 // 2.6.0-12.0.pre.443
33+ // 2.6.0-12.0.pre-443
3334 //
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
3539 // separate the main semantic version from the pre release version.
36- final splitOnSpaces = versionString .split (' ' );
40+ final splitOnSpaces = canonicalized .split (' ' );
3741 final version = splitOnSpaces.first;
3842 final splitOnDash = version.split ('-' );
3943 assert (splitOnDash.length <= 2 , 'version: $version ' );
@@ -115,6 +119,16 @@ class SemanticVersion with CompareMixin<SemanticVersion> {
115119
116120 int ? preReleaseMinor;
117121
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+
118132 bool get isPreRelease => preReleaseMajor != null || preReleaseMinor != null ;
119133
120134 bool isSupported ({required SemanticVersion minSupportedVersion}) =>
0 commit comments