Skip to content

Commit

Permalink
fix(gradle): Accept versions with trailing separators as valid (#33884)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov authored Jan 27, 2025
1 parent 6be155d commit 563cdab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/modules/versioning/gradle/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions lib/modules/versioning/gradle/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down

0 comments on commit 563cdab

Please sign in to comment.