Skip to content

Commit

Permalink
fix: Trim whitespace before parsing Version
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins committed Jan 14, 2025
1 parent 906d432 commit 5e60901
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion AWSSDKSwiftCLI/Sources/AWSCLIUtils/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 5e60901

Please sign in to comment.