Skip to content

Commit 290b4fc

Browse files
committed
Change version comparison logic
The central server sends a short version (e.g. 0.14), which the distributed server then compares to its long version (e.g. 0.14.1). The problem is that 0.14 compares as less than 0.14.1, so language packs are shown as unavailable. Instead, when comparing two mismatched-length versions, only consider the shortest version available -- thus 0.14 and 0.14.1 would compare equal. Then the languagepack versions will be compared, which is the actual intent.
1 parent 306de74 commit 290b4fc

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

kalite/updates/static/js/updates/update_languages.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ var installed_languages = [];
33
var downloading = false;
44

55
function version_comparison(v1, v2) {
6-
// compare two version strings and return 1 if the first is higher than the second,
7-
// -1 if the first is lower than the second, and 0 if they are equal
6+
/*
7+
compare two version strings and return 1 if the first is higher than the second,
8+
-1 if the first is lower than the second, and 0 if they are equal.
9+
10+
:params v1, v2: Version strings expected format is either "N.N.N" or "N.N", where N is a positive integer.
11+
If both strings have the same format, they're compared using a lexical order.
12+
If one string is shorter than the other, then the other is truncated and then compared using lexical order.
13+
*/
814
var v1parts = v1.split('.'), v2parts = v2.split('.');
9-
var maxLen = Math.max(v1parts.length, v2parts.length);
15+
var minLen = Math.min(v1parts.length, v2parts.length);
1016
var part1, part2;
11-
for(var i = 0; i < maxLen; i++) {
17+
for(var i = 0; i < minLen; i++) {
1218
part1 = parseInt(v1parts[i], 10) || 0;
1319
part2 = parseInt(v2parts[i], 10) || 0;
1420
if (part1 > part2) return 1;

0 commit comments

Comments
 (0)