mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #15282 from CorpGlory/unexpected-semver-comparison-behavior-#15280
Unexpected semver comparison behavior #15280
This commit is contained in:
commit
8f0e9b674d
@ -20,12 +20,25 @@ export class SemVersion {
|
||||
|
||||
isGtOrEq(version: string): boolean {
|
||||
const compared = new SemVersion(version);
|
||||
return !(this.major < compared.major || this.minor < compared.minor || this.patch < compared.patch);
|
||||
|
||||
for (let i = 0; i < this.comparable.length; ++i) {
|
||||
if (this.comparable[i] > compared.comparable[i]) {
|
||||
return true;
|
||||
}
|
||||
if (this.comparable[i] < compared.comparable[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
isValid(): boolean {
|
||||
return _.isNumber(this.major);
|
||||
}
|
||||
|
||||
get comparable() {
|
||||
return [this.major, this.minor, this.patch];
|
||||
}
|
||||
}
|
||||
|
||||
export function isVersionGtOrEq(a: string, b: string): boolean {
|
||||
|
@ -44,6 +44,7 @@ describe('SemVersion', () => {
|
||||
{ values: ['3.1.1-beta1', '3.1'], expected: true },
|
||||
{ values: ['3.4.5', '4'], expected: false },
|
||||
{ values: ['3.4.5', '3.5'], expected: false },
|
||||
{ values: ['6.0.0', '5.2.0'], expected: true },
|
||||
];
|
||||
cases.forEach(testCase => {
|
||||
expect(isVersionGtOrEq(testCase.values[0], testCase.values[1])).toBe(testCase.expected);
|
Loading…
Reference in New Issue
Block a user