From 20059d977bc0970f67da2ecf894769d7fd185fb6 Mon Sep 17 00:00:00 2001
From: Sergio Zharinov <zharinov@users.noreply.github.com>
Date: Wed, 8 Jul 2020 20:40:33 +0400
Subject: [PATCH] fix(maven): Avoid range downgrades (#6711)

---
 lib/versioning/maven/compare.ts    | 6 ++++--
 lib/versioning/maven/index.spec.ts | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/versioning/maven/compare.ts b/lib/versioning/maven/compare.ts
index 375c394226..7b49ffc2ee 100644
--- a/lib/versioning/maven/compare.ts
+++ b/lib/versioning/maven/compare.ts
@@ -520,8 +520,10 @@ function autoExtendMavenRange(
     rightValue !== null &&
     incrementRangeValue(leftValue) === rightValue
   ) {
-    interval.leftValue = coerceRangeValue(leftValue, newValue);
-    interval.rightValue = incrementRangeValue(interval.leftValue);
+    if (compare(newValue, leftValue) !== -1) {
+      interval.leftValue = coerceRangeValue(leftValue, newValue);
+      interval.rightValue = incrementRangeValue(interval.leftValue);
+    }
   } else if (rightValue !== null) {
     if (interval.rightType === INCLUDING_POINT) {
       const tokens = tokenize(rightValue);
diff --git a/lib/versioning/maven/index.spec.ts b/lib/versioning/maven/index.spec.ts
index cb74cea649..b401c53588 100644
--- a/lib/versioning/maven/index.spec.ts
+++ b/lib/versioning/maven/index.spec.ts
@@ -257,7 +257,7 @@ describe('versioning/maven/compare', () => {
       ['[1.2.3,)', '1.2.4', '[1.2.4,)'],
       ['[1.2.3,[', '1.2.4', '[1.2.4,['],
       ['[1.2.3,]', '1.2.4', '[1.2.3,]'], // invalid range
-      ['[0.21,0.22)', '0.20.21', '[0.20,0.21)'],
+      ['[0.21,0.22)', '0.20.21', '[0.21,0.22)'],
       ['[0.21,0.22)', '0.21.1', '[0.21,0.22)'],
       ['[0.21,0.22.0)', '0.22.1', '[0.21,0.22.2)'],
       ['[0.21,0.22)', '0.23', '[0.23,0.24)'],
-- 
GitLab