Skip to content

Fix crash on invalid Swift language version #3380

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
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion Sources/PackageLoading/PackageDescription4Loader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ enum ManifestJSONParser {
}

return try versionJSON.map {
try SwiftLanguageVersion(string: String(json: $0))!
let languageVersionString = try String(json: $0)
guard let languageVersion = SwiftLanguageVersion(string: languageVersionString) else {
throw ManifestParseError.runtimeManifestErrors(["invalid Swift language version: \(languageVersionString)"])
}
return languageVersion
}
}

Expand Down
20 changes: 20 additions & 0 deletions Tests/PackageLoadingTests/PD5_0LoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,26 @@ class PackageDescription5_0LoadingTests: PackageDescriptionLoadingTests {
XCTAssertMatch(message, .contains("'v3' is unavailable"))
XCTAssertMatch(message, .contains("'v3' was obsoleted in PackageDescription 5"))
}

stream = BufferedOutputByteStream()
stream <<< """
import PackageDescription
let package = Package(
name: "Foo",
swiftLanguageVersions: [.version("")]
)
"""

do {
try loadManifestThrowing(stream.bytes) { _ in }
XCTFail()
} catch {
guard case let ManifestParseError.runtimeManifestErrors(messages) = error else {
return XCTFail("unexpected error: \(error)")
}

XCTAssertEqual(messages, ["invalid Swift language version: "])
}
}

func testPlatformOptions() throws {
Expand Down