diff --git a/AWSSDKSwiftCLI/Sources/AWSCLIUtils/Version.swift b/AWSSDKSwiftCLI/Sources/AWSCLIUtils/Version.swift index ec42553cc34..892f8a3d4d8 100644 --- a/AWSSDKSwiftCLI/Sources/AWSCLIUtils/Version.swift +++ b/AWSSDKSwiftCLI/Sources/AWSCLIUtils/Version.swift @@ -22,7 +22,7 @@ public struct Version: Equatable { } public init(_ value: String) throws { - let components = value.split(separator: ".") + let components = value.trimmingCharacters(in: .whitespacesAndNewlines).split(separator: ".") guard components.count == 3 else { throw Error("Version does not have three components") } diff --git a/AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Utils/VersionUtilsTests.swift b/AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Utils/VersionUtilsTests.swift index 211cc3bfb35..9b2c03a98db 100644 --- a/AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Utils/VersionUtilsTests.swift +++ b/AWSSDKSwiftCLI/Tests/AWSSDKSwiftCLITests/Utils/VersionUtilsTests.swift @@ -10,7 +10,14 @@ import AWSCLIUtils import XCTest class VersionUtilsTests: XCTestCase { - + + func testIgnoresLeadingAndTrailingWhitespace() throws { + try XCTAssertEqual( + Version("\r\n\t 1.2.1\r\n\t "), + Version("1.2.1") + ) + } + func testIncrementingMajor() throws { try XCTAssertEqual( Version("1.2.1").incrementingMajor(),