Skip to content
Snippets Groups Projects
Unverified Commit 563cdabc authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

fix(gradle): Accept versions with trailing separators as valid (#33884)

parent 6be155da
No related branches found
Tags 39.137.1
No related merge requests found
......@@ -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;
......
......@@ -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);
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment