diff --git a/lib/config/validation.spec.ts b/lib/config/validation.spec.ts index fdea879c615fa83eb0b376a82ad3bec8e10f7e1d..7798ceaebba2fdf323b8c335ba117a2b71c536ff 100644 --- a/lib/config/validation.spec.ts +++ b/lib/config/validation.spec.ts @@ -89,6 +89,10 @@ describe('config/validation', () => { matchPackageNames: ['quack'], allowedVersions: '!/***$}{]][/', }, + { + matchPackageNames: ['quack'], + allowedVersions: '/quaCk/i', + }, ], }; const { errors } = await configValidation.validateConfig(false, config); @@ -114,6 +118,11 @@ describe('config/validation', () => { matchCurrentValue: '<1.0.0', enabled: true, }, + { + matchPackageNames: ['foo'], + matchCurrentValue: '/^2/i', + enabled: true, + }, ], }; const { errors } = await configValidation.validateConfig(false, config); @@ -143,6 +152,11 @@ describe('config/validation', () => { matchCurrentVersion: '!/***$}{]][/', enabled: true, }, + { + matchPackageNames: ['foo'], + matchCurrentVersion: '/^2/i', + enabled: true, + }, ], }; const { errors } = await configValidation.validateConfig(false, config); @@ -218,7 +232,7 @@ describe('config/validation', () => { it('catches invalid baseBranches regex', async () => { const config = { - baseBranches: ['/***$}{]][/'], + baseBranches: ['/***$}{]][/', '/branch/i'], }; const { errors } = await configValidation.validateConfig(false, config); expect(errors).toEqual([ diff --git a/lib/util/package-rules/current-value.spec.ts b/lib/util/package-rules/current-value.spec.ts index 8c6b096f02c16ada5e23d6e1a87bc9aecd571445..55e2f8bd66ad9cd15a6d5f4b628112c1f44e0da8 100644 --- a/lib/util/package-rules/current-value.spec.ts +++ b/lib/util/package-rules/current-value.spec.ts @@ -28,6 +28,18 @@ describe('util/package-rules/current-value', () => { expect(result).toBeFalse(); }); + it('case insensitive match', () => { + const result = matcher.matches( + { + currentValue: '"V1.1.0"', + }, + { + matchCurrentValue: '/^"v/i', + }, + ); + expect(result).toBeTrue(); + }); + it('return true for regex version match', () => { const result = matcher.matches( { diff --git a/lib/util/package-rules/current-version.spec.ts b/lib/util/package-rules/current-version.spec.ts index de7db7b9c4ae745d7613be7b5b7c056a8a9fa966..d8b8ee034df1a4078fe314f4b1c4d82f23036fc4 100644 --- a/lib/util/package-rules/current-version.spec.ts +++ b/lib/util/package-rules/current-version.spec.ts @@ -50,6 +50,19 @@ describe('util/package-rules/current-version', () => { expect(result).toBeFalse(); }); + it('case insensitive match', () => { + const result = matcher.matches( + { + versioning: 'pep440', + currentValue: 'bbbbbb', + }, + { + matchCurrentVersion: '/BBB.*/i', + }, + ); + expect(result).toBeTrue(); + }); + it('return false for regex version non match', () => { const result = matcher.matches( { diff --git a/lib/util/regex.spec.ts b/lib/util/regex.spec.ts index 833d42e626a3987c712f96fa1b1904028a69209a..c2b0265e282cc2b8c0a9eccdbf8e45aa601123b2 100644 --- a/lib/util/regex.spec.ts +++ b/lib/util/regex.spec.ts @@ -1,6 +1,6 @@ import RE2 from 're2'; import { CONFIG_VALIDATION } from '../constants/error-messages'; -import { isUUID, regEx } from './regex'; +import { configRegexPredicate, isUUID, regEx } from './regex'; describe('util/regex', () => { beforeEach(() => { @@ -45,4 +45,26 @@ describe('util/regex', () => { expect(isUUID('not-a-uuid')).toBe(false); }); }); + + describe('configRegexPredicate', () => { + it('allows valid regex pattern', () => { + expect(configRegexPredicate('/hello/')).not.toBeNull(); + }); + + it('invalidates invalid regex pattern', () => { + expect(configRegexPredicate('/^test\\d+$/m')).toBeNull(); + }); + + it('allows the i flag in regex pattern', () => { + expect(configRegexPredicate('/^test\\d+$/i')).not.toBeNull(); + }); + + it('allows negative regex pattern', () => { + expect(configRegexPredicate('!/^test\\d+$/i')).not.toBeNull(); + }); + + it('does not allow non-regex input', () => { + expect(configRegexPredicate('hello')).toBeNull(); + }); + }); }); diff --git a/lib/util/regex.ts b/lib/util/regex.ts index 60289ad1ee8643129154516c9d7801f58d6accc5..94a5522dbf65afc7f23d510e7f867062d7f9d3e1 100644 --- a/lib/util/regex.ts +++ b/lib/util/regex.ts @@ -65,7 +65,7 @@ export function escapeRegExp(input: string): string { export const newlineRegex = regEx(/\r?\n/); const configValStart = regEx(/^!?\//); -const configValEnd = regEx(/\/$/); +const configValEnd = regEx(/\/i?$/); export function isConfigRegex(input: unknown): input is string { return ( @@ -78,7 +78,7 @@ function parseConfigRegex(input: string): RegExp | null { const regexString = input .replace(configValStart, '') .replace(configValEnd, ''); - return regEx(regexString); + return input.endsWith('i') ? regEx(regexString, 'i') : regEx(regexString); } catch (err) { // no-op } diff --git a/lib/workers/global/autodiscover.spec.ts b/lib/workers/global/autodiscover.spec.ts index e1934e2b049cbaf579513b09612f78b9b9a97f2f..bca4cf969d3da202884abce14ec58b3cb15e9d5a 100644 --- a/lib/workers/global/autodiscover.spec.ts +++ b/lib/workers/global/autodiscover.spec.ts @@ -107,7 +107,7 @@ describe('workers/global/autodiscover', () => { it('filters autodiscovered github repos with regex', async () => { config.autodiscover = true; - config.autodiscoverFilter = ['/project/re*./']; + config.autodiscoverFilter = ['/project/RE*./i']; config.platform = 'github'; hostRules.find = jest.fn(() => ({ token: 'abc', diff --git a/lib/workers/repository/process/index.spec.ts b/lib/workers/repository/process/index.spec.ts index 4bcf83e03c551579fa5ad2623df206538cbd22ed..95006f1deab99fae75dd78fc30a718bd3928b08a 100644 --- a/lib/workers/repository/process/index.spec.ts +++ b/lib/workers/repository/process/index.spec.ts @@ -126,10 +126,11 @@ describe('workers/repository/process/index', () => { it('finds baseBranches via regular expressions', async () => { extract.mockResolvedValue({} as never); - config.baseBranches = ['/^release\\/.*/', 'dev', '!/^pre-release\\/.*/']; + config.baseBranches = ['/^release\\/.*/i', 'dev', '!/^pre-release\\/.*/']; git.getBranchList.mockReturnValue([ 'dev', 'pre-release/v0', + 'RELEASE/v0', 'release/v1', 'release/v2', 'some-other', @@ -137,15 +138,24 @@ describe('workers/repository/process/index', () => { scm.branchExists.mockResolvedValue(true); const res = await extractDependencies(config); expect(res).toStrictEqual({ - branchList: [undefined, undefined, undefined, undefined], - branches: [undefined, undefined, undefined, undefined], + branchList: [undefined, undefined, undefined, undefined, undefined], + branches: [undefined, undefined, undefined, undefined, undefined], packageFiles: undefined, }); expect(logger.logger.debug).toHaveBeenCalledWith( - { baseBranches: ['release/v1', 'release/v2', 'dev', 'some-other'] }, + { + baseBranches: [ + 'RELEASE/v0', + 'release/v1', + 'release/v2', + 'dev', + 'some-other', + ], + }, 'baseBranches', ); + expect(addMeta).toHaveBeenCalledWith({ baseBranch: 'RELEASE/v0' }); expect(addMeta).toHaveBeenCalledWith({ baseBranch: 'release/v1' }); expect(addMeta).toHaveBeenCalledWith({ baseBranch: 'release/v2' }); expect(addMeta).toHaveBeenCalledWith({ baseBranch: 'dev' });