growthbook / growthbook-swift

GrowthBook iOS (Swift) SDK
MIT License
13 stars 19 forks source link

Strings with version format are not compared as versions #38

Closed HeEAaD closed 1 year ago

HeEAaD commented 1 year ago

The version 0.9.0 is smaller then 0.10.0, therefore

ConditionEvaluator().isEvalOperatorCondition(operatorKey: "$vlt", attributeValue: "0.9.0", conditionValue: "0.10.0")

should return true.

Actual result: The mention method call returns false. Expected result: The mention method call returns true.

Environment:

GrowthBook 1.0.38

Steps to reproduce:

Use the follow test to reproduce the issue:

@testable import GrowthBook
import XCTest

final class GrowthBookTests: XCTestCase {
    func test_condition_vlt() {
        let sut = ConditionEvaluator()
        XCTAssertTrue(sut.isEvalOperatorCondition(operatorKey: "$vlt", attributeValue: "0.9.0", conditionValue: "0.10.0"))
    }
}
vazarkevych commented 1 year ago

Hello @HeEAaD, Thank you for bringing the version comparison issue in GrowthBook version 1.0.38 to our attention. We appreciate your detailed report, which helped us diagnose and fix the problem quickly. I'm pleased to inform you that we've addressed the issue and released a new version that includes the fix. You should be able to see the expected behavior now when using ConditionEvaluator().isEvalOperatorCondition() with version numbers like "0.9.0" and "0.10.0". Please update to the latest version and let us know if everything is working as expected or if you encounter any further issues. Thanks again for your valuable feedback.

HeEAaD commented 1 year ago

Thank you @vazarkevych for the fast fix. I can confirm that the described issue is resolved for the mentioned case.

I want to make you aware of an edge case that can crash the application in GrowthBook 1.0.42: String(repeating: " ", count: 5 - $0.count) will crash for versions with 6-digit components. For example, the following test case will crash:

XCTAssertTrue(sut.isEvalOperatorCondition(operatorKey: "$veq", attributeValue: "0.123456.0", conditionValue: "0.123456.0"))

This is no issue in my company's project but might be relevant for other customers.