From b6ed33ec012d13d814f7a27df4d620cb57c5ad40 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Mon, 30 Jan 2023 07:37:24 +0100 Subject: [PATCH] =?UTF-8?q?fix(regex):=20don=E2=80=99t=20escape=20forward?= =?UTF-8?q?=20slash=20in=20fileMatch=20(#19314)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This cleanup of default `fileMatch` values should be backwards compatible. --- docs/usage/configuration-options.md | 4 ++-- lib/config/options/index.ts | 2 +- lib/config/presets/internal/group.ts | 2 +- lib/config/presets/internal/monorepo.ts | 2 +- lib/modules/datasource/deno/index.ts | 2 +- lib/modules/datasource/go/releases-goproxy.ts | 4 ++-- lib/modules/datasource/hermit/index.ts | 2 +- lib/modules/datasource/maven/index.ts | 2 +- lib/modules/datasource/pypi/common.ts | 2 +- lib/modules/manager/bazelisk/index.ts | 2 +- lib/modules/manager/cocoapods/extract.ts | 2 +- lib/modules/manager/flux/common.ts | 2 +- lib/modules/manager/fvm/index.ts | 2 +- lib/modules/manager/github-actions/index.ts | 4 ++-- lib/modules/manager/gitlabci/utils.ts | 2 +- lib/modules/manager/gradle/index.ts | 8 ++++---- lib/modules/manager/mint/index.ts | 2 +- lib/modules/manager/nix/index.ts | 2 +- lib/modules/manager/nuget/index.ts | 4 ++-- lib/modules/manager/pre-commit/extract.ts | 2 +- lib/modules/manager/puppet/index.ts | 2 +- lib/modules/manager/regex/readme.md | 4 ++-- lib/modules/manager/terraform/lockfile/hash.ts | 2 +- lib/modules/manager/terraform/lockfile/util.ts | 2 +- lib/modules/manager/woodpecker/index.ts | 2 +- lib/modules/versioning/kubernetes-api/index.ts | 2 +- lib/util/modules.ts | 5 ++--- .../repository/update/pr/changelog/release-notes.ts | 4 ++-- 28 files changed, 38 insertions(+), 39 deletions(-) diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md index 1e86f6a106..2f27ba582f 100644 --- a/docs/usage/configuration-options.md +++ b/docs/usage/configuration-options.md @@ -1809,7 +1809,7 @@ This field also supports Regular Expressions if they begin and end with `/`. e.g { "packageRules": [ { - "matchBaseBranches": ["/^release\\/.*/"], + "matchBaseBranches": ["/^release/.*/"], "excludePackagePatterns": ["^eslint"], "enabled": false } @@ -2782,7 +2782,7 @@ regex definition: { "fileMatch": ["values.yaml$"], "matchStrings": [ - "image:\\s+(?<depName>my\\.old\\.registry\\/aRepository\\/andImage):(?<currentValue>[^\\s]+)" + "image:\\s+(?<depName>my\\.old\\.registry/aRepository/andImage):(?<currentValue>[^\\s]+)" ], "depNameTemplate": "my.new.registry/aRepository/andImage", "autoReplaceStringTemplate": "image: {{{depName}}}:{{{newValue}}}", diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index dc6b4c3339..e062c7f02e 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -962,7 +962,7 @@ const options: RenovateOptions[] = [ { name: 'matchBaseBranches', description: - 'List of strings containing exact matches (e.g. `["main"]`) and/or regex expressions (e.g. `["/^release\\/.*/"]`). Valid only within a `packageRules` object.', + 'List of strings containing exact matches (e.g. `["main"]`) and/or regex expressions (e.g. `["/^release/.*/"]`). Valid only within a `packageRules` object.', type: 'array', subType: 'string', allowString: true, diff --git a/lib/config/presets/internal/group.ts b/lib/config/presets/internal/group.ts index 18a9bf8d2f..4e4d71da78 100644 --- a/lib/config/presets/internal/group.ts +++ b/lib/config/presets/internal/group.ts @@ -314,7 +314,7 @@ const staticGroups = { { groupName: 'PHPStan packages', matchDatasources: ['packagist'], - matchPackagePatterns: ['^phpstan\\/phpstan$', '\\/phpstan-'], + matchPackagePatterns: ['^phpstan/phpstan$', '/phpstan-'], }, ], }, diff --git a/lib/config/presets/internal/monorepo.ts b/lib/config/presets/internal/monorepo.ts index a471cdfbce..930bf6a3f7 100644 --- a/lib/config/presets/internal/monorepo.ts +++ b/lib/config/presets/internal/monorepo.ts @@ -270,7 +270,7 @@ const patternGroups = { clarity: ['^@cds/', '^@clr/'], embroider: '^@embroider/', fullcalendar: '^@fullcalendar/', - spfx: ['^@microsoft\\/sp-', '^@microsoft\\/eslint-.+-spfx$'], + spfx: ['^@microsoft/sp-', '^@microsoft/eslint-.+-spfx$'], spock: '^org\\.spockframework:spock-', 'syncfusion-dotnet': '^Syncfusion\\.', wordpress: '^@wordpress/', diff --git a/lib/modules/datasource/deno/index.ts b/lib/modules/datasource/deno/index.ts index 1568c1d5cd..81b42542b5 100644 --- a/lib/modules/datasource/deno/index.ts +++ b/lib/modules/datasource/deno/index.ts @@ -45,7 +45,7 @@ export class DenoDatasource extends Datasource { const massagedRegistryUrl = registryUrl!; const extractResult = regEx( - '^(https:\\/\\/deno.land\\/)(?<rawPackageName>[^@\\s]+)' + '^(https://deno.land/)(?<rawPackageName>[^@\\s]+)' ).exec(packageName); const rawPackageName = extractResult?.groups?.rawPackageName; if (is.nullOrUndefined(rawPackageName)) { diff --git a/lib/modules/datasource/go/releases-goproxy.ts b/lib/modules/datasource/go/releases-goproxy.ts index c3dd78d160..a541c06c28 100644 --- a/lib/modules/datasource/go/releases-goproxy.ts +++ b/lib/modules/datasource/go/releases-goproxy.ts @@ -161,11 +161,11 @@ export class GoProxyDatasource extends Datasource { }, asterisk: { match: '*', - value: (_: string) => '[^\\/]*', + value: (_: string) => '[^/]*', }, qmark: { match: '?', - value: (_: string) => '[^\\/]', + value: (_: string) => '[^/]', }, characterRangeOpen: { match: '[', diff --git a/lib/modules/datasource/hermit/index.ts b/lib/modules/datasource/hermit/index.ts index f2015d3385..cb95421f5f 100644 --- a/lib/modules/datasource/hermit/index.ts +++ b/lib/modules/datasource/hermit/index.ts @@ -34,7 +34,7 @@ export class HermitDatasource extends Datasource { constructor() { super(HermitDatasource.id); this.http = new GithubHttp(id); - this.pathRegex = regEx('^\\/(?<owner>[^/]+)\\/(?<repo>[^/]+)$'); + this.pathRegex = regEx('^/(?<owner>[^/]+)/(?<repo>[^/]+)$'); } @cache({ diff --git a/lib/modules/datasource/maven/index.ts b/lib/modules/datasource/maven/index.ts index 19e327ec7d..a257edfcde 100644 --- a/lib/modules/datasource/maven/index.ts +++ b/lib/modules/datasource/maven/index.ts @@ -53,7 +53,7 @@ function extractVersions(metadata: XmlDocument): string[] { } const mavenCentralHtmlVersionRegex = regEx( - '^<a href="(?<version>[^"]+)\\/" title="(?:[^"]+)\\/">(?:[^"]+)\\/<\\/a>\\s+(?<releaseTimestamp>\\d\\d\\d\\d-\\d\\d-\\d\\d \\d\\d:\\d\\d)\\s+-$', + '^<a href="(?<version>[^"]+)/" title="(?:[^"]+)/">(?:[^"]+)/</a>\\s+(?<releaseTimestamp>\\d\\d\\d\\d-\\d\\d-\\d\\d \\d\\d:\\d\\d)\\s+-$', 'i' ); diff --git a/lib/modules/datasource/pypi/common.ts b/lib/modules/datasource/pypi/common.ts index 50310011e5..ea46fddcc7 100644 --- a/lib/modules/datasource/pypi/common.ts +++ b/lib/modules/datasource/pypi/common.ts @@ -1,6 +1,6 @@ import { regEx } from '../../../util/regex'; -const githubRepoPattern = regEx(/^https?:\/\/github\.com\/[^\\/]+\/[^\\/]+$/); +const githubRepoPattern = regEx(/^https?:\/\/github\.com\/[^/]+\/[^/]+$/); export function isGitHubRepo(url: string): boolean { return !url.includes('sponsors') && githubRepoPattern.test(url); diff --git a/lib/modules/manager/bazelisk/index.ts b/lib/modules/manager/bazelisk/index.ts index 345989e1b4..350125b3b3 100644 --- a/lib/modules/manager/bazelisk/index.ts +++ b/lib/modules/manager/bazelisk/index.ts @@ -3,7 +3,7 @@ import { GithubReleasesDatasource } from '../../datasource/github-releases'; export { extractPackageFile } from './extract'; export const defaultConfig = { - fileMatch: ['(^|\\/)\\.bazelversion$'], + fileMatch: ['(^|/)\\.bazelversion$'], pinDigests: false, }; diff --git a/lib/modules/manager/cocoapods/extract.ts b/lib/modules/manager/cocoapods/extract.ts index e251df745d..ddb17826e7 100644 --- a/lib/modules/manager/cocoapods/extract.ts +++ b/lib/modules/manager/cocoapods/extract.ts @@ -9,7 +9,7 @@ import type { PackageDependency, PackageFileContent } from '../types'; import type { ParsedLine } from './types'; const regexMappings = [ - regEx(`^\\s*pod\\s+(['"])(?<spec>[^'"/]+)(\\/(?<subspec>[^'"]+))?(['"])`), + regEx(`^\\s*pod\\s+(['"])(?<spec>[^'"/]+)(/(?<subspec>[^'"]+))?(['"])`), regEx( `^\\s*pod\\s+(['"])[^'"]+(['"])\\s*,\\s*(['"])(?<currentValue>[^'"]+)(['"])\\s*$` ), diff --git a/lib/modules/manager/flux/common.ts b/lib/modules/manager/flux/common.ts index 320e7b9f31..3d9b97896f 100644 --- a/lib/modules/manager/flux/common.ts +++ b/lib/modules/manager/flux/common.ts @@ -1,7 +1,7 @@ import { regEx } from '../../../util/regex'; export const systemManifestRegex = - '(^|\\/)flux-system\\/(?:.+\\/)?gotk-components\\.yaml$'; + '(^|/)flux-system/(?:.+/)?gotk-components\\.yaml$'; export function isSystemManifest(file: string): boolean { return regEx(systemManifestRegex).test(file); diff --git a/lib/modules/manager/fvm/index.ts b/lib/modules/manager/fvm/index.ts index 68b30f3138..ebb67637e3 100644 --- a/lib/modules/manager/fvm/index.ts +++ b/lib/modules/manager/fvm/index.ts @@ -6,6 +6,6 @@ export { extractPackageFile } from './extract'; export const supportedDatasources = [FlutterVersionDatasource.id]; export const defaultConfig = { - fileMatch: ['(^|\\/)\\.fvm\\/fvm_config\\.json$'], + fileMatch: ['(^|/)\\.fvm/fvm_config\\.json$'], versioning: semverVersioning.id, }; diff --git a/lib/modules/manager/github-actions/index.ts b/lib/modules/manager/github-actions/index.ts index 8d6dc9282c..c2d7ad80bb 100644 --- a/lib/modules/manager/github-actions/index.ts +++ b/lib/modules/manager/github-actions/index.ts @@ -4,8 +4,8 @@ export { extractPackageFile } from './extract'; export const defaultConfig = { fileMatch: [ - '^(workflow-templates|\\.github\\/workflows)\\/[^/]+\\.ya?ml$', - '(^|\\/)action\\.ya?ml$', + '^(workflow-templates|\\.github/workflows)/[^/]+\\.ya?ml$', + '(^|/)action\\.ya?ml$', ], }; diff --git a/lib/modules/manager/gitlabci/utils.ts b/lib/modules/manager/gitlabci/utils.ts index d8afde40ba..15f094742b 100644 --- a/lib/modules/manager/gitlabci/utils.ts +++ b/lib/modules/manager/gitlabci/utils.ts @@ -16,7 +16,7 @@ export function replaceReferenceTags(content: string): string { } const depProxyRe = regEx( - `(?<prefix>\\$\\{?CI_DEPENDENCY_PROXY_(?:DIRECT_)?GROUP_IMAGE_PREFIX\\}?\\/)(?<depName>.+)` + `(?<prefix>\\$\\{?CI_DEPENDENCY_PROXY_(?:DIRECT_)?GROUP_IMAGE_PREFIX\\}?/)(?<depName>.+)` ); /** diff --git a/lib/modules/manager/gradle/index.ts b/lib/modules/manager/gradle/index.ts index bb0ce8edd1..ad83ff7f60 100644 --- a/lib/modules/manager/gradle/index.ts +++ b/lib/modules/manager/gradle/index.ts @@ -12,12 +12,12 @@ export const supportsLockFileMaintenance = true; export const defaultConfig = { fileMatch: [ '\\.gradle(\\.kts)?$', - '(^|\\/)gradle\\.properties$', - '(^|\\/)gradle\\/.+\\.toml$', + '(^|/)gradle\\.properties$', + '(^|/)gradle/.+\\.toml$', '\\.versions\\.toml$', // The two below is for gradle-consistent-versions plugin - `(^|\\/)versions.props$`, - `(^|\\/)versions.lock$`, + `(^|/)versions.props$`, + `(^|/)versions.lock$`, ], timeout: 600, versioning: gradleVersioning.id, diff --git a/lib/modules/manager/mint/index.ts b/lib/modules/manager/mint/index.ts index 34ac584580..fffd5aadb1 100644 --- a/lib/modules/manager/mint/index.ts +++ b/lib/modules/manager/mint/index.ts @@ -8,5 +8,5 @@ export { extractPackageFile } from './extract'; export const supportedDatasources = [GitTagsDatasource.id]; export const defaultConfig = { - fileMatch: ['(^|\\/)Mintfile$'], + fileMatch: ['(^|/)Mintfile$'], }; diff --git a/lib/modules/manager/nix/index.ts b/lib/modules/manager/nix/index.ts index 58b43af484..7cdfa48cde 100644 --- a/lib/modules/manager/nix/index.ts +++ b/lib/modules/manager/nix/index.ts @@ -6,7 +6,7 @@ export { updateArtifacts } from './artifacts'; export const supportsLockFileMaintenance = true; export const defaultConfig = { - fileMatch: ['(^|\\/)flake\\.nix$'], + fileMatch: ['(^|/)flake\\.nix$'], commitMessageTopic: 'nixpkgs', commitMessageExtra: 'to {{newValue}}', enabled: false, diff --git a/lib/modules/manager/nuget/index.ts b/lib/modules/manager/nuget/index.ts index 8f2a3253eb..c34ca3a67d 100644 --- a/lib/modules/manager/nuget/index.ts +++ b/lib/modules/manager/nuget/index.ts @@ -12,8 +12,8 @@ export const defaultConfig = { fileMatch: [ '\\.(?:cs|fs|vb)proj$', '\\.(?:props|targets)$', - '(^|\\/)dotnet-tools\\.json$', - '(^|\\/)global\\.json$', + '(^|/)dotnet-tools\\.json$', + '(^|/)global\\.json$', ], }; diff --git a/lib/modules/manager/pre-commit/extract.ts b/lib/modules/manager/pre-commit/extract.ts index f7450cf713..7c9fba7561 100644 --- a/lib/modules/manager/pre-commit/extract.ts +++ b/lib/modules/manager/pre-commit/extract.ts @@ -83,7 +83,7 @@ function extractDependency( const urlMatchers = [ // This splits "http://my.github.com/user/repo" -> "my.github.com" "user/repo - regEx('^https?:\\/\\/(?<hostname>[^\\/]+)\\/(?<depName>\\S*)'), + regEx('^https?://(?<hostname>[^/]+)/(?<depName>\\S*)'), // This splits "git@private.registry.com:user/repo" -> "private.registry.com" "user/repo regEx('^git@(?<hostname>[^:]+):(?<depName>\\S*)'), // This split "git://github.com/pre-commit/pre-commit-hooks" -> "github.com" "pre-commit/pre-commit-hooks" diff --git a/lib/modules/manager/puppet/index.ts b/lib/modules/manager/puppet/index.ts index 8743d2d408..2b0735bb4c 100644 --- a/lib/modules/manager/puppet/index.ts +++ b/lib/modules/manager/puppet/index.ts @@ -8,7 +8,7 @@ export { extractPackageFile } from './extract'; export const language: ProgrammingLanguage = 'ruby'; export const defaultConfig = { - fileMatch: ['(^|\\/)Puppetfile$'], + fileMatch: ['(^|/)Puppetfile$'], }; export const supportedDatasources = [ diff --git a/lib/modules/manager/regex/readme.md b/lib/modules/manager/regex/readme.md index a4a0ab6185..3adba3802f 100644 --- a/lib/modules/manager/regex/readme.md +++ b/lib/modules/manager/regex/readme.md @@ -180,8 +180,8 @@ For example: "fileMatch": [".*y[a]?ml$"], "matchStringsStrategy": "combination", "matchStrings": [ - "['\"]?(?<depName>/pipeline-fragments\\/fragment-version-check)['\"]?\\s*ref:\\s['\"]?(?<currentValue>[\\d-]*)['\"]?", - "['\"]?(?<depName>pipeline-solutions\\/gitlab\\/fragments\\/fragment-version-check)['\"]?\\s*ref:\\s['\"]?(?<currentValue>[\\d-]*)['\"]?" + "['\"]?(?<depName>/pipeline-fragments/fragment-version-check)['\"]?\\s*ref:\\s['\"]?(?<currentValue>[\\d-]*)['\"]?", + "['\"]?(?<depName>pipeline-solutions/gitlab/fragments/fragment-version-check)['\"]?\\s*ref:\\s['\"]?(?<currentValue>[\\d-]*)['\"]?" ], "depNameTemplate": "pipeline-solutions/gitlab/fragments/fragment-version-check", "autoReplaceStringTemplate": "'{{{depName}}}'\n ref: {{{newValue}}}", diff --git a/lib/modules/manager/terraform/lockfile/hash.ts b/lib/modules/manager/terraform/lockfile/hash.ts index d3b3757163..25afff41e2 100644 --- a/lib/modules/manager/terraform/lockfile/hash.ts +++ b/lib/modules/manager/terraform/lockfile/hash.ts @@ -32,7 +32,7 @@ export class TerraformProviderHash { // add double space, the filename and a new line char rootHash.update(' '); - const fileName = file.replace(regEx(/^.*[\\/]/), ''); + const fileName = file.replace(regEx(/^.*[/]/), ''); rootHash.update(fileName); rootHash.update('\n'); } diff --git a/lib/modules/manager/terraform/lockfile/util.ts b/lib/modules/manager/terraform/lockfile/util.ts index 774be9e728..2f59bb1e56 100644 --- a/lib/modules/manager/terraform/lockfile/util.ts +++ b/lib/modules/manager/terraform/lockfile/util.ts @@ -10,7 +10,7 @@ import type { } from './types'; const providerStartLineRegex = regEx( - `^provider "(?<registryUrl>[^/]*)\\/(?<namespace>[^/]*)\\/(?<depName>[^/]*)"` + `^provider "(?<registryUrl>[^/]*)/(?<namespace>[^/]*)/(?<depName>[^/]*)"` ); const versionLineRegex = regEx( `^(?<prefix>[\\s]*version[\\s]*=[\\s]*")(?<version>[^"']+)(?<suffix>".*)$` diff --git a/lib/modules/manager/woodpecker/index.ts b/lib/modules/manager/woodpecker/index.ts index aa823a82e0..07a0c38a5c 100644 --- a/lib/modules/manager/woodpecker/index.ts +++ b/lib/modules/manager/woodpecker/index.ts @@ -7,7 +7,7 @@ export const language: ProgrammingLanguage = 'docker'; export { extractPackageFile }; export const defaultConfig = { - fileMatch: ['^\\.woodpecker(?:\\/[^/]+)?\\.ya?ml$'], + fileMatch: ['^\\.woodpecker(?:/[^/]+)?\\.ya?ml$'], }; export const supportedDatasources = [DockerDatasource.id]; diff --git a/lib/modules/versioning/kubernetes-api/index.ts b/lib/modules/versioning/kubernetes-api/index.ts index c620991813..afcdf95438 100644 --- a/lib/modules/versioning/kubernetes-api/index.ts +++ b/lib/modules/versioning/kubernetes-api/index.ts @@ -10,7 +10,7 @@ export const supportsRanges = false; export class KubernetesApiVersioningApi extends RegExpVersioningApi { private static readonly versionRegex = - '^(?:(?<compatibility>\\S+)\\/)?v(?<major>\\d+)(?<prerelease>(?:alpha|beta)\\d+)?$'; + '^(?:(?<compatibility>\\S+)/)?v(?<major>\\d+)(?<prerelease>(?:alpha|beta)\\d+)?$'; public constructor() { super(KubernetesApiVersioningApi.versionRegex); diff --git a/lib/util/modules.ts b/lib/util/modules.ts index e0bc3596cc..f0c6d49913 100644 --- a/lib/util/modules.ts +++ b/lib/util/modules.ts @@ -1,10 +1,9 @@ import fs from 'fs'; import upath from 'upath'; -import { regEx } from './regex'; function relatePath(here: string, there: string): string { - const thereParts = upath.normalizeTrim(there).split(regEx(/[\\/]/)); - const hereParts = upath.normalizeTrim(here).split(regEx(/[\\/]/)); + const thereParts = upath.normalizeTrim(there).split('/'); + const hereParts = upath.normalizeTrim(here).split('/'); let idx = 0; while ( diff --git a/lib/workers/repository/update/pr/changelog/release-notes.ts b/lib/workers/repository/update/pr/changelog/release-notes.ts index 31446797c7..2cb7d2fbae 100644 --- a/lib/workers/repository/update/pr/changelog/release-notes.ts +++ b/lib/workers/repository/update/pr/changelog/release-notes.ts @@ -82,7 +82,7 @@ export function massageBody( body = body.replace(regEx(/^<a name="[^"]*"><\/a>\n/), ''); body = body.replace( regEx( - `^##? \\[[^\\]]*\\]\\(${baseUrl}[^/]*\\/[^/]*\\/compare\\/.*?\\n`, + `^##? \\[[^\\]]*\\]\\(${baseUrl}[^/]*/[^/]*/compare/.*?\\n`, undefined, false ), @@ -90,7 +90,7 @@ export function massageBody( ); // Clean-up unnecessary commits link body = `\n${body}\n`.replace( - regEx(`\\n${baseUrl}[^/]+\\/[^/]+\\/compare\\/[^\\n]+(\\n|$)`), + regEx(`\\n${baseUrl}[^/]+/[^/]+/compare/[^\\n]+(\\n|$)`), '\n' ); // Reduce headings size -- GitLab