diff --git a/lib/modules/versioning/gradle/compare.ts b/lib/modules/versioning/gradle/compare.ts index 2497527108363a590977c027531769f0e6670201..afc808ef4e05f8ab1817b204cfbc763299642590 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 323b0d2e433488bf8ec2bf32521f67e2df4cf074..04be6d5f481d636d541d402a05c36c5db2b85dcf 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); });