From b753ba47edda6e84d1f953b1bd08a50ba05af354 Mon Sep 17 00:00:00 2001 From: Namyalg Date: Mon, 2 Dec 2024 15:17:19 +0530 Subject: [PATCH 1/4] fix: equality comparison for semantic version comparison when number of segments = max allowed segments --- src/remote-config/condition-evaluator-internal.ts | 6 +++++- test/unit/remote-config/condition-evaluator.spec.ts | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/remote-config/condition-evaluator-internal.ts b/src/remote-config/condition-evaluator-internal.ts index c0fc0484a8..78f2d1652d 100644 --- a/src/remote-config/condition-evaluator-internal.ts +++ b/src/remote-config/condition-evaluator-internal.ts @@ -302,6 +302,10 @@ function compareSemanticVersions( const version1 = String(actualValue).split('.').map(Number); const version2 = targetValue.split('.').map(Number); + if (version1.length > MAX_LENGTH || version2.length > MAX_LENGTH) { + return false; + } + for (let i = 0; i < MAX_LENGTH; i++) { // Check to see if segments are present. Note that these may be present and be NaN. const version1HasSegment = version1[i] !== undefined; @@ -321,5 +325,5 @@ function compareSemanticVersions( if (version1[i] < version2[i]) return predicateFn(-1); if (version1[i] > version2[i]) return predicateFn(1); } - return false; + return predicateFn(0); } diff --git a/test/unit/remote-config/condition-evaluator.spec.ts b/test/unit/remote-config/condition-evaluator.spec.ts index 8bfa168df6..4fd9aff899 100644 --- a/test/unit/remote-config/condition-evaluator.spec.ts +++ b/test/unit/remote-config/condition-evaluator.spec.ts @@ -1114,6 +1114,7 @@ describe('ConditionEvaluator', () => { { targets: ['5.12.3'], actual: '5.11.9', outcome: true }, { targets: ['5.12.3'], actual: '5.12.3', outcome: true }, { targets: ['5.12.3'], actual: '5.12.9', outcome: false }, + { targets: ['5.6.7.8.9'], actual: '5.6.7.8.9', outcome: true }, invalidNumericSignalTestCase, ]; @@ -1127,6 +1128,8 @@ describe('ConditionEvaluator', () => { { targets: ['5.0'], actual: 5.0, outcome: true }, { targets: ['5.12.3'], actual: '5.12.9', outcome: false }, { targets: ['5.12.3'], actual: '5.12.3.0.0.0.0', outcome: false }, + { targets: ['5.6.7.8.9'], actual: '5.6.7.8.9', outcome: true }, + { targets: ['5.6.7.8.9.0'], actual: '5.6.7.8.9.0', outcome: false }, invalidNumericSignalTestCase, ]; @@ -1166,6 +1169,7 @@ describe('ConditionEvaluator', () => { { targets: ['5'], actual: 5.0, outcome: true }, { targets: ['5.0'], actual: 5.0, outcome: true }, { targets: ['5.12.3'], actual: '5.11.9', outcome: false }, + { targets: ['5.6.7.8.9'], actual: '5.6.7.8.9', outcome: true }, invalidNumericSignalTestCase ]; From 03b6c97828a8dee532d6fbe3d513ab0d60b02a0c Mon Sep 17 00:00:00 2001 From: Namyalg Date: Tue, 3 Dec 2024 05:14:52 +0530 Subject: [PATCH 2/4] minor refactor --- src/remote-config/condition-evaluator-internal.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/remote-config/condition-evaluator-internal.ts b/src/remote-config/condition-evaluator-internal.ts index 78f2d1652d..2c39dba816 100644 --- a/src/remote-config/condition-evaluator-internal.ts +++ b/src/remote-config/condition-evaluator-internal.ts @@ -311,9 +311,6 @@ function compareSemanticVersions( const version1HasSegment = version1[i] !== undefined; const version2HasSegment = version2[i] !== undefined; - // If both are undefined, we've consumed everything and they're equal. - if (!version1HasSegment && !version2HasSegment) return predicateFn(0) - // Insert zeros if undefined for easier comparison. if (!version1HasSegment) version1[i] = 0; if (!version2HasSegment) version2[i] = 0; @@ -325,5 +322,6 @@ function compareSemanticVersions( if (version1[i] < version2[i]) return predicateFn(-1); if (version1[i] > version2[i]) return predicateFn(1); } + // If this point is reached, the semantic versions equal. return predicateFn(0); } From 9ff76f9f8c93addfa1c03f42f03e4045b00beb4c Mon Sep 17 00:00:00 2001 From: Namya LG <53875297+Namyalg@users.noreply.github.com> Date: Tue, 3 Dec 2024 05:16:14 +0530 Subject: [PATCH 3/4] Update condition-evaluator-internal.ts --- src/remote-config/condition-evaluator-internal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/remote-config/condition-evaluator-internal.ts b/src/remote-config/condition-evaluator-internal.ts index 2c39dba816..b49b35dc8d 100644 --- a/src/remote-config/condition-evaluator-internal.ts +++ b/src/remote-config/condition-evaluator-internal.ts @@ -322,6 +322,6 @@ function compareSemanticVersions( if (version1[i] < version2[i]) return predicateFn(-1); if (version1[i] > version2[i]) return predicateFn(1); } - // If this point is reached, the semantic versions equal. + // If this point is reached, the semantic versions are equal. return predicateFn(0); } From 9907a754e0c6a55759f3780458ee4bd5b935e035 Mon Sep 17 00:00:00 2001 From: Namyalg Date: Mon, 9 Dec 2024 22:18:37 +0530 Subject: [PATCH 4/4] chore:update UT --- test/unit/remote-config/condition-evaluator.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/remote-config/condition-evaluator.spec.ts b/test/unit/remote-config/condition-evaluator.spec.ts index 4fd9aff899..7368457fcf 100644 --- a/test/unit/remote-config/condition-evaluator.spec.ts +++ b/test/unit/remote-config/condition-evaluator.spec.ts @@ -1129,6 +1129,7 @@ describe('ConditionEvaluator', () => { { targets: ['5.12.3'], actual: '5.12.9', outcome: false }, { targets: ['5.12.3'], actual: '5.12.3.0.0.0.0', outcome: false }, { targets: ['5.6.7.8.9'], actual: '5.6.7.8.9', outcome: true }, + { targets: ['5.6.7.8.9'], actual: '4.5.6.7.8', outcome: false }, { targets: ['5.6.7.8.9.0'], actual: '5.6.7.8.9.0', outcome: false }, invalidNumericSignalTestCase, ];