Skip to content

Commit 15df439

Browse files
add check to see that all dot notated areas are numbers. (#357)
1 parent 0919abe commit 15df439

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

Sources/Data Model/Audience/SemanticVersion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ extension SemanticVersion {
8888
throw OptimizelyError.attributeFormatInvalid
8989
}
9090
var targetedVersionParts = targetPrefix.split(separator: ".")
91-
guard targetedVersionParts.count == dotCount + 1 else {
91+
guard targetedVersionParts.count == dotCount + 1 && targetedVersionParts.filter({$0.isNumber}).count == targetedVersionParts.count else {
9292
throw OptimizelyError.attributeFormatInvalid
9393
}
9494
if let targetSuffix = targetSuffix {

Tests/OptimizelyTests-DataModel/SemanticVersionTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ class SemanticVersionTests: XCTestCase {
165165

166166
func testInvalidAttributes() {
167167
let target = "2.1.0"
168-
let versions = ["-", ".", "..", "+", "+test", " ", "2 .3. 0", "2.", ".2.2", "3.7.2.2"]
168+
let versions = ["-", ".", "..", "+", "+test", " ", "2 .3. 0", "2.", ".2.2", "3.7.2.2", "3.x",
169+
",", "+build-prerelese"]
169170
for (_, version) in versions.enumerated() {
170171
XCTAssert(((try? (version.compareVersion(targetedVersion: target)) < 0) == nil))
171172
}

0 commit comments

Comments
 (0)