Skip to content
Merged
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
16 changes: 16 additions & 0 deletions Sources/PackageDescription/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public struct Version {
/// - patch: The patch version number.
/// - prereleaseIdentifiers: The pre-release identifier.
/// - buildMetaDataIdentifiers: Build metadata that identifies a build.
///
/// - Precondition: `major >= 0 && minor >= 0 && patch >= 0`.
/// - Precondition: `prereleaseIdentifiers` can conatin only ASCII alpha-numeric characters and "-".
/// - Precondition: `buildMetaDataIdentifiers` can conatin only ASCII alpha-numeric characters and "-".
public init(
_ major: Int,
_ minor: Int,
Expand All @@ -68,6 +72,18 @@ public struct Version {
buildMetadataIdentifiers: [String] = []
) {
precondition(major >= 0 && minor >= 0 && patch >= 0, "Negative versioning is invalid.")
precondition(
prereleaseIdentifiers.allSatisfy {
$0.allSatisfy { $0.isASCII && ($0.isLetter || $0.isNumber || $0 == "-") }
},
#"Pre-release identifiers can contain only ASCII alpha-numeric characters and "-"."#
)
precondition(
buildMetadataIdentifiers.allSatisfy {
$0.allSatisfy { $0.isASCII && ($0.isLetter || $0.isNumber || $0 == "-") }
},
#"Build metadata identifiers can contain only ASCII alpha-numeric characters and "-"."#
)
self.major = major
self.minor = minor
self.patch = patch
Expand Down