diff --git a/pkgs/pub_semver/CHANGELOG.md b/pkgs/pub_semver/CHANGELOG.md index a31fbb2437..4f6fc26fa0 100644 --- a/pkgs/pub_semver/CHANGELOG.md +++ b/pkgs/pub_semver/CHANGELOG.md @@ -1,3 +1,11 @@ +## 2.1.6 + +- Clarify that the lists returned by + the `preRelease` and `build` properties of `Version` and + the `ranges` property of `VersionUnion` should not be modified. +- Note that `VersionConstraint.any` and `VersionConstraint.empty` static fields + shouldn't be reassigned and will be made `final` in a future release. + ## 2.1.5 - Require Dart `3.4.0`. diff --git a/pkgs/pub_semver/lib/src/version.dart b/pkgs/pub_semver/lib/src/version.dart index 90f3d535fd..732aea0bb5 100644 --- a/pkgs/pub_semver/lib/src/version.dart +++ b/pkgs/pub_semver/lib/src/version.dart @@ -70,6 +70,8 @@ class Version implements VersionConstraint, VersionRange { /// This is split into a list of components, each of which may be either a /// string or a non-negative integer. It may also be empty, indicating that /// this version has no pre-release identifier. + /// + /// **Note:** The returned list shouldn't be modified. final List preRelease; /// The build identifier: "foo" in "1.2.3+foo". @@ -77,6 +79,8 @@ class Version implements VersionConstraint, VersionRange { /// This is split into a list of components, each of which may be either a /// string or a non-negative integer. It may also be empty, indicating that /// this version has no build identifier. + /// + /// **Note:** The returned list shouldn't be modified. final List build; /// The original string representation of the version number. @@ -96,8 +100,10 @@ class Version implements VersionConstraint, VersionRange { Version._(this.major, this.minor, this.patch, String? preRelease, String? build, this._text) - : preRelease = preRelease == null ? [] : _splitParts(preRelease), - build = build == null ? [] : _splitParts(build) { + : preRelease = preRelease == null || preRelease.isEmpty + ? [] + : _splitParts(preRelease), + build = build == null || build.isEmpty ? [] : _splitParts(build) { if (major < 0) throw ArgumentError('Major version must be non-negative.'); if (minor < 0) throw ArgumentError('Minor version must be non-negative.'); if (patch < 0) throw ArgumentError('Patch version must be non-negative.'); diff --git a/pkgs/pub_semver/lib/src/version_constraint.dart b/pkgs/pub_semver/lib/src/version_constraint.dart index 948118ef3b..de17fb5a83 100644 --- a/pkgs/pub_semver/lib/src/version_constraint.dart +++ b/pkgs/pub_semver/lib/src/version_constraint.dart @@ -16,9 +16,15 @@ import 'version_union.dart'; /// version. abstract class VersionConstraint { /// A [VersionConstraint] that allows all versions. + /// + /// **Note:** This property shouldn't be reassigned. + /// It will be made `final` in a future release. static VersionConstraint any = VersionRange(); /// A [VersionConstraint] that allows no versions -- the empty set. + /// + /// **Note:** This property shouldn't be reassigned. + /// It will be made `final` in a future release. static VersionConstraint empty = const _EmptyVersion(); /// Parses a version constraint. diff --git a/pkgs/pub_semver/lib/src/version_union.dart b/pkgs/pub_semver/lib/src/version_union.dart index 844d3b8eff..24cca0a7e3 100644 --- a/pkgs/pub_semver/lib/src/version_union.dart +++ b/pkgs/pub_semver/lib/src/version_union.dart @@ -23,6 +23,8 @@ class VersionUnion implements VersionConstraint { /// * Its contents are disjoint and non-adjacent. In other words, for any two /// constraints next to each other in the list, there's some version between /// those constraints that they don't match. + /// + /// **Note:** The returned list shouldn't be modified. final List ranges; @override diff --git a/pkgs/pub_semver/pubspec.yaml b/pkgs/pub_semver/pubspec.yaml index 536826a4c7..ac0aca7be0 100644 --- a/pkgs/pub_semver/pubspec.yaml +++ b/pkgs/pub_semver/pubspec.yaml @@ -1,5 +1,5 @@ name: pub_semver -version: 2.1.5 +version: 2.1.6 description: >- Versions and version constraints implementing pub's versioning policy. This is very similar to vanilla semver, with a few corner cases.