Skip to content

Commit

Permalink
Merge branch 'master' into rc-client-serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
kjelko authored Feb 11, 2025
2 parents 112ddfb + cb2b92f commit 03dbccc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/remote-config/condition-evaluator-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,15 @@ 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;
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;
Expand All @@ -321,5 +322,6 @@ function compareSemanticVersions(
if (version1[i] < version2[i]) return predicateFn(-1);
if (version1[i] > version2[i]) return predicateFn(1);
}
return false;
// If this point is reached, the semantic versions are equal.
return predicateFn(0);
}
5 changes: 5 additions & 0 deletions test/unit/remote-config/condition-evaluator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];

Expand All @@ -1127,6 +1128,9 @@ 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'], 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,
];

Expand Down Expand Up @@ -1166,6 +1170,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
];

Expand Down

0 comments on commit 03dbccc

Please sign in to comment.