You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by at...@apache.org on 2015/01/16 15:17:39 UTC
ambari git commit: AMBARI-9174 Improve compare method of repository
versions. (atkach)
Repository: ambari
Updated Branches:
refs/heads/trunk 0a1d66488 -> e465ddad2
AMBARI-9174 Improve compare method of repository versions. (atkach)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e465ddad
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e465ddad
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e465ddad
Branch: refs/heads/trunk
Commit: e465ddad25787127408c6e511add11157c9f4714
Parents: 0a1d664
Author: Andrii Tkach <at...@hortonworks.com>
Authored: Fri Jan 16 15:32:34 2015 +0200
Committer: Andrii Tkach <at...@hortonworks.com>
Committed: Fri Jan 16 16:16:50 2015 +0200
----------------------------------------------------------------------
ambari-web/app/utils/string_utils.js | 18 +++++++++---------
ambari-web/test/utils/string_utils_test.js | 3 +++
2 files changed, 12 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/e465ddad/ambari-web/app/utils/string_utils.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/string_utils.js b/ambari-web/app/utils/string_utils.js
index f3a5eeb..7a451bd 100644
--- a/ambari-web/app/utils/string_utils.js
+++ b/ambari-web/app/utils/string_utils.js
@@ -82,35 +82,35 @@ module.exports = {
* @param second {string}
* @return {number}
*/
- compareVersions: function(first, second){
+ compareVersions: function (first, second) {
if (!(typeof first === 'string' && typeof second === 'string')) {
return -1;
}
if (first === '' || second === '') {
return -1;
}
- var firstNumbers = first.split('.');
- var secondNumbers = second.split('.');
+ var firstNumbers = first.split(/[\.-]/);
+ var secondNumbers = second.split(/[\.-]/);
var length = 0;
var i = 0;
var result = false;
- if(firstNumbers.length === secondNumbers.length) {
+ if (firstNumbers.length === secondNumbers.length) {
length = firstNumbers.length;
- } else if(firstNumbers.length < secondNumbers.length){
+ } else if (firstNumbers.length < secondNumbers.length) {
length = secondNumbers.length;
} else {
length = firstNumbers.length;
}
- while(i < length && !result){
+ while (i < length && !result) {
firstNumbers[i] = (firstNumbers[i] === undefined) ? 0 : window.parseInt(firstNumbers[i]);
secondNumbers[i] = (secondNumbers[i] === undefined) ? 0 : window.parseInt(secondNumbers[i]);
- if(firstNumbers[i] > secondNumbers[i]){
+ if (firstNumbers[i] > secondNumbers[i]) {
result = 1;
break;
- } else if(firstNumbers[i] === secondNumbers[i]){
+ } else if (firstNumbers[i] === secondNumbers[i]) {
result = 0;
- } else if(firstNumbers[i] < secondNumbers[i]){
+ } else if (firstNumbers[i] < secondNumbers[i]) {
result = -1;
break;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/e465ddad/ambari-web/test/utils/string_utils_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/utils/string_utils_test.js b/ambari-web/test/utils/string_utils_test.js
index 711915f..625aa75 100644
--- a/ambari-web/test/utils/string_utils_test.js
+++ b/ambari-web/test/utils/string_utils_test.js
@@ -63,6 +63,9 @@ describe('string_utils', function () {
{m: '1.2.1 higher than 1.2', v1:'1.2.1', v2:'1.2', e: 1},
{m: '11.2 higher than 2.2', v1:'11.2', v2:'2.2', e: 1},
{m: '0.9 higher than 0.8', v1:'0.9', v2:'0.8', e: 1},
+ {m: '1.1-2 equal to 1.1-2 ', v1:'1.1-2', v2:'1.1-2', e: 0},
+ {m: '1.1-2 higher than 1.1-1', v1:'1.1-2', v2:'1.1-1', e: 1},
+ {m: '1.1-4 lower than 1.1-46', v1:'1.1-4', v2:'1.1-46', e: -1},
{m: 'return false if no string passed', v1: '0.9', e: -1}
];
tests.forEach(function(test) {