Skip to content

Correctly validate characters in semantic version identifiers #3839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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