Skip to content

Commit

Permalink
fix: regEx definitions that used regex literal and separate flags (#2…
Browse files Browse the repository at this point in the history
…4626)

Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
gost-serb and rarkins committed Sep 24, 2023
1 parent 71a86f2 commit 6759c6f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/modules/datasource/conan/__fixtures__/mixed_case.json
@@ -0,0 +1,3 @@
{
"results": [ "FooBar/1.0.0@_/_", "FooBar/1.1.0@_/_", "FooBar/2.2.0@_/_" ]
}
3 changes: 1 addition & 2 deletions lib/modules/datasource/conan/common.ts
Expand Up @@ -6,8 +6,7 @@ export const defaultRegistryUrl = 'https://center.conan.io/';
export const datasource = 'conan';

export const conanDatasourceRegex = regEx(
/(?<name>[a-z\-_0-9]+)\/(?<version>[^@/\n]+)(?<userChannel>@\S+\/\S+)/,
'gim'
/(?<name>[a-z\-_0-9]+)\/(?<version>[^@/\n]+)(?<userChannel>@\S+\/\S+)/gim
);

export function getConanPackage(packageName: string): ConanPackage {
Expand Down
27 changes: 27 additions & 0 deletions lib/modules/datasource/conan/index.spec.ts
Expand Up @@ -6,6 +6,7 @@ import type { GetDigestInputConfig, GetPkgReleasesConfig } from '../types';
import { defaultRegistryUrl } from './common';
import { ConanDatasource } from '.';

const mixedCaseJson = Fixtures.get('mixed_case.json');
const pocoJson = Fixtures.get('poco.json');
const pocoRevisions = Fixtures.getJson('poco_revisions.json');
const pocoYamlGitHubContent = Fixtures.get('poco.yaml');
Expand Down Expand Up @@ -150,6 +151,32 @@ describe('modules/datasource/conan/index', () => {
});
});

it('processes mixed case names', async () => {
httpMock
.scope(nonDefaultRegistryUrl)
.get('/v2/conans/search?q=FooBar')
.reply(200, mixedCaseJson);
expect(
await getPkgReleases({
...config,
packageName: 'FooBar/1.0.0@_/_',
})
).toEqual({
registryUrl: 'https://not.conan.io',
releases: [
{
version: '1.0.0',
},
{
version: '1.1.0',
},
{
version: '2.2.0',
},
],
});
});

it('uses github instead of conan center', async () => {
httpMock
.scope('https://api.github.com')
Expand Down
1 change: 1 addition & 0 deletions lib/modules/datasource/conan/index.ts
Expand Up @@ -140,6 +140,7 @@ export class ConanDatasource extends Datasource {
const dep: ReleaseResult = { releases: [] };

for (const resultString of Object.values(versions.results ?? {})) {
conanDatasourceRegex.lastIndex = 0;
const fromMatch = conanDatasourceRegex.exec(resultString);
if (fromMatch?.groups?.version && fromMatch?.groups?.userChannel) {
const version = fromMatch.groups.version;
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/swift/extract.ts
Expand Up @@ -5,7 +5,7 @@ import type { MatchResult } from './types';

const regExps = {
wildcard: regEx(/^.*?/),
space: regEx(/(\s+|\/\/[^\n]*|\/\*.*\*\/)+/, 's'),
space: regEx(/(\s+|\/\/[^\n]*|\/\*.*\*\/)+/s),
depsKeyword: regEx(/dependencies/),
colon: regEx(/:/),
beginSection: regEx(/\[/),
Expand Down
1 change: 1 addition & 0 deletions lib/util/regex.spec.ts
Expand Up @@ -41,6 +41,7 @@ describe('util/regex', () => {
describe('isUUID', () => {
it('proper checks valid and invalid UUID strings', () => {
expect(isUUID('{90b6646d-1724-4a64-9fd9-539515fe94e9}')).toBe(true);
expect(isUUID('{90B6646D-1724-4A64-9FD9-539515FE94E9}')).toBe(true);
expect(isUUID('not-a-uuid')).toBe(false);
});
});
Expand Down
3 changes: 1 addition & 2 deletions lib/util/regex.ts
Expand Up @@ -102,8 +102,7 @@ export function configRegexPredicate(
}

const UUIDRegex = regEx(
/^\{[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\}$/,
'i'
/^\{[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\}$/i
);

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

0 comments on commit 6759c6f

Please sign in to comment.