From 563cdabc66cc7bef2270811d7ac7a3c169f88eaa Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Mon, 27 Jan 2025 17:00:54 -0300 Subject: [PATCH] fix(gradle): Accept versions with trailing separators as valid (#33884) --- lib/modules/versioning/gradle/compare.ts | 18 ++++++++++-------- lib/modules/versioning/gradle/index.spec.ts | 10 ++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/modules/versioning/gradle/compare.ts b/lib/modules/versioning/gradle/compare.ts index 2497527108363a..afc808ef4e05f8 100644 --- a/lib/modules/versioning/gradle/compare.ts +++ b/lib/modules/versioning/gradle/compare.ts @@ -49,10 +49,6 @@ export function tokenize(versionStr: string): Token[] | null { let currentVal = ''; function yieldToken(): void { - if (currentVal === '') { - // We tried to yield an empty token, which means we're in a bad state. - result = null; - } if (result) { const val = currentVal; if (regEx(/^\d+$/).test(val)) { @@ -73,8 +69,12 @@ export function tokenize(versionStr: string): Token[] | null { if (nextChar === null) { yieldToken(); } else if (isSeparator(nextChar)) { - yieldToken(); - currentVal = ''; + if (prevChar && !isSeparator(prevChar)) { + yieldToken(); + currentVal = ''; + } else { + result = null; + } } else if (prevChar !== null && isTransition(prevChar, nextChar)) { yieldToken(); currentVal = nextChar; @@ -243,11 +243,13 @@ export function parsePrefixRange(input: string): PrefixRange | null { return { tokens: [] }; } - const postfixRegex = regEx(/[-._]\+$/); + const postfixRegex = regEx(/[^-._+][-._]\+$/); if (postfixRegex.test(input)) { const prefixValue = input.replace(regEx(/[-._]\+$/), ''); const tokens = tokenize(prefixValue); - return tokens ? { tokens } : null; + if (tokens) { + return { tokens }; + } } return null; diff --git a/lib/modules/versioning/gradle/index.spec.ts b/lib/modules/versioning/gradle/index.spec.ts index 323b0d2e433488..04be6d5f481d63 100644 --- a/lib/modules/versioning/gradle/index.spec.ts +++ b/lib/modules/versioning/gradle/index.spec.ts @@ -78,6 +78,8 @@ describe('modules/versioning/gradle/index', () => { ${'1.0-sp-1'} | ${'1.0-release'} | ${1} ${'1.0-sp-2'} | ${'1.0-sp-1'} | ${1} ${''} | ${''} | ${0} + ${'384.vf35b_f26814ec'} | ${'400.v35420b_922dcb_'} | ${-1} + ${'___'} | ${'...'} | ${0} `('compare("$a", "$b") === $expected', ({ a, b, expected }) => { expect(compare(a, b)).toEqual(expected); }); @@ -158,6 +160,14 @@ describe('modules/versioning/gradle/index', () => { ${'1++2'} | ${false} ${'1--2'} | ${false} ${'1__2'} | ${false} + ${'400.v35420b_922dcb_'} | ${true} + ${'400.v35420b_922dcb'} | ${true} + ${'__'} | ${false} + ${'_.'} | ${false} + ${'._'} | ${false} + ${'_+'} | ${false} + ${'+.'} | ${false} + ${'.+'} | ${false} `('isVersion("$input") === $expected', ({ input, expected }) => { expect(api.isVersion(input)).toBe(expected); });