Skip to content

Commit

Permalink
Apply same logic for string package "coordinates"
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Apr 22, 2023
1 parent c4ae04c commit 0fe94e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
11 changes: 4 additions & 7 deletions lib/modules/manager/gradle/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ describe('modules/manager/gradle/utils', () => {
it('versionLikeSubstring', () => {
[
'1.2.3',
'foobar',
'[1.0,2.0]',
'(,2.0[',
'2.1.1.RELEASE',
'1.0.+',
'2022-05-10_55',
'latest',
].forEach((input) => {
expect(versionLikeSubstring(input)).toEqual(input);
expect(versionLikeSubstring(`${input}'`)).toEqual(input);
Expand All @@ -31,12 +29,14 @@ describe('modules/manager/gradle/utils', () => {
expect(versionLikeSubstring('')).toBeNull();
expect(versionLikeSubstring(undefined)).toBeNull();
expect(versionLikeSubstring(null)).toBeNull();
expect(versionLikeSubstring('foobar')).toBeNull();
expect(versionLikeSubstring('latest')).toBeNull();
});

it('isDependencyString', () => {
expect(isDependencyString('foo:bar:1.2.3')).toBeTrue();
expect(isDependencyString('foo.foo:bar.bar:1.2.3')).toBeTrue();
expect(isDependencyString('foo:bar:baz:qux')).toBeTrue();
expect(isDependencyString('foo:bar:baz:qux')).toBeFalse();
expect(isDependencyString('foo.bar:baz:1.2.3')).toBeTrue();
expect(isDependencyString('foo.bar:baz:1.2.3:linux-cpu-x86_64')).toBeTrue();
expect(isDependencyString('foo.bar:baz:1.2.+')).toBeTrue();
Expand All @@ -57,10 +57,6 @@ describe('modules/manager/gradle/utils', () => {
depName: 'foo.foo:bar.bar',
currentValue: '1.2.3',
});
expect(parseDependencyString('foo:bar:baz:qux')).toMatchObject({
depName: 'foo:bar',
currentValue: 'baz',
});
expect(parseDependencyString('foo.bar:baz:1.2.3')).toMatchObject({
depName: 'foo.bar:baz',
currentValue: '1.2.3',
Expand All @@ -69,6 +65,7 @@ describe('modules/manager/gradle/utils', () => {
depName: 'foo:bar',
currentValue: '1.2.+',
});
expect(parseDependencyString('foo:bar:baz:qux')).toBeNull();
expect(parseDependencyString('foo:bar:baz:qux:quux')).toBeNull();
expect(parseDependencyString("foo:bar:1.2.3'")).toBeNull();
expect(parseDependencyString('foo:bar:1.2.3"')).toBeNull();
Expand Down
13 changes: 11 additions & 2 deletions lib/modules/manager/gradle/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@ const versionLikeRegex = regEx('^(?<version>[-_.\\[\\](),a-zA-Z0-9+]+)');
export function versionLikeSubstring(
input: string | null | undefined
): string | null {
const match = input ? versionLikeRegex.exec(input) : null;
return match?.groups?.version ?? null;
if (!input) {
return null;
}

const match = versionLikeRegex.exec(input);
const version = match?.groups?.version;
if (!version || !regEx(/\d/).test(version)) {
return null;
}

return version;
}

export function isDependencyString(input: string): boolean {
Expand Down

0 comments on commit 0fe94e7

Please sign in to comment.