From 88f6b987d56f5828cf2375a848535cc3cc6260b7 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Tue, 4 Apr 2023 16:06:20 +0200
Subject: [PATCH] fix(versioning/hashicorp): allow numbered unstable versions
 (#21334)

---
 lib/modules/versioning/hashicorp/convertor.spec.ts | 1 +
 lib/modules/versioning/hashicorp/convertor.ts      | 6 ++++--
 lib/modules/versioning/hashicorp/index.spec.ts     | 1 +
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/modules/versioning/hashicorp/convertor.spec.ts b/lib/modules/versioning/hashicorp/convertor.spec.ts
index bd3ed56e47..c46be23ef5 100644
--- a/lib/modules/versioning/hashicorp/convertor.spec.ts
+++ b/lib/modules/versioning/hashicorp/convertor.spec.ts
@@ -18,6 +18,7 @@ describe('modules/versioning/hashicorp/convertor', () => {
     ${'< 4.0'}          | ${'<4.0'}
     ${'> 4.0, < 5.0'}   | ${'>4.0 <5.0'}
     ${'~> 2.3.4'}       | ${'~2.3.4'}
+    ${'0.1.0-beta.0'}   | ${'0.1.0-beta.0'}
   `(
     'hashicorp2npm("$hashicorp") === $npm && npm2hashicorp("$npm") === $hashicorp',
     ({ hashicorp, npm }) => {
diff --git a/lib/modules/versioning/hashicorp/convertor.ts b/lib/modules/versioning/hashicorp/convertor.ts
index 9f784f58f8..ffff6416d7 100644
--- a/lib/modules/versioning/hashicorp/convertor.ts
+++ b/lib/modules/versioning/hashicorp/convertor.ts
@@ -14,7 +14,9 @@ export function hashicorp2npm(input: string): string {
     .split(',')
     .map((single) => {
       const r = single.match(
-        regEx(/^\s*(|=|!=|>|<|>=|<=|~>)\s*v?((\d+)(\.\d+){0,2}[\w-+]*)\s*$/)
+        regEx(
+          /^\s*(|=|!=|>|<|>=|<=|~>)\s*v?((\d+)(\.\d+){0,2}[\w-+]*(\.\d+)*)\s*$/
+        )
       );
       if (!r) {
         logger.warn(
@@ -64,7 +66,7 @@ export function npm2hashicorp(input: string): string {
     .split(' ')
     .map((single) => {
       const r = single.match(
-        regEx(/^(|>|<|>=|<=|~|\^)v?((\d+)(\.\d+){0,2}[\w-]*)$/)
+        regEx(/^(|>|<|>=|<=|~|\^)v?((\d+)(\.\d+){0,2}[\w-]*(\.\d+)*)$/)
       );
       if (!r) {
         throw new Error('invalid npm constraint');
diff --git a/lib/modules/versioning/hashicorp/index.spec.ts b/lib/modules/versioning/hashicorp/index.spec.ts
index cc6bcede70..f1eae889e3 100644
--- a/lib/modules/versioning/hashicorp/index.spec.ts
+++ b/lib/modules/versioning/hashicorp/index.spec.ts
@@ -36,6 +36,7 @@ describe('modules/versioning/hashicorp/index', () => {
     ${'>=4.1'}              | ${true}
     ${'<=4.1.2'}            | ${true}
     ${''}                   | ${false}
+    ${'0.1.0-beta.0'}       | ${true}
   `('isValid("$input") === $expected', ({ input, expected }) => {
     const res = !!semver.isValid(input);
     expect(res).toBe(expected);
-- 
GitLab