latestVersion() relies on original version list ascii ordering as a last resort

Fixes #436
This commit is contained in:
Thaddee Tyl 2015-05-05 22:50:44 +02:00
parent ae875a7633
commit ada1817f13

View File

@ -2048,6 +2048,7 @@ cache(function(data, match, sendBadge, request) {
if (err != null) { if (err != null) {
badgeData.text[1] = 'inaccessible'; badgeData.text[1] = 'inaccessible';
sendBadge(format, badgeData); sendBadge(format, badgeData);
return;
} }
try { try {
if ((+res.headers['x-ratelimit-remaining']) === 0) { if ((+res.headers['x-ratelimit-remaining']) === 0) {
@ -3700,13 +3701,15 @@ function versionColor(version) {
// Given a list of versions (as strings), return the latest version. // Given a list of versions (as strings), return the latest version.
function latestVersion(versions) { function latestVersion(versions) {
var version = ''; var version = '';
var origVersions = versions;
versions = versions.filter(function(version) { versions = versions.filter(function(version) {
return (/^v?[0-9]/).test(version); return (/^v?[0-9]/).test(version);
}); });
semver_versions = versions.map(function(version) { semver_versions = versions.map(function(version) {
var matches = /^(v?[0-9]+)(\.[0-9]+)?(-.*)?$/.exec(version); var matches = /^(v?[0-9]+)(\.[0-9]+)?(-.*)?$/.exec(version);
if (matches) { if (matches) {
version = matches[1] + (matches[2] ? matches[2] : '.0') + '.0' + (matches[3] ? matches[3] : ''); version = matches[1] + (matches[2] ? matches[2] : '.0') + '.0' +
(matches[3] ? matches[3] : '');
} }
return version; return version;
}); });
@ -3717,6 +3720,10 @@ function latestVersion(versions) {
versions = versions.sort(); versions = versions.sort();
version = versions[versions.length - 1]; version = versions[versions.length - 1];
} }
if (version === undefined) {
origVersions = origVersions.sort();
version = origVersions[origVersions.length - 1];
}
return version; return version;
} }