Skip to content

Commit

Permalink
fix(regex): don’t escape forward slash in fileMatch (#19314)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 4, 2023
1 parent 1fadf7b commit fdeba67
Show file tree
Hide file tree
Showing 28 changed files with 38 additions and 39 deletions.
4 changes: 2 additions & 2 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ This field also supports Regular Expressions if they begin and end with `/`. e.g
{
"packageRules": [
{
"matchBaseBranches": ["/^release\\/.*/"],
"matchBaseBranches": ["/^release/.*/"],
"excludePackagePatterns": ["^eslint"],
"enabled": false
}
Expand Down Expand Up @@ -2712,7 +2712,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}}}",
Expand Down
2 changes: 1 addition & 1 deletion lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,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,
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ const staticGroups = {
{
groupName: 'PHPStan packages',
matchDatasources: ['packagist'],
matchPackagePatterns: ['^phpstan\\/phpstan$', '\\/phpstan-'],
matchPackagePatterns: ['^phpstan/phpstan$', '/phpstan-'],
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/monorepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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$'],
'syncfusion-dotnet': '^Syncfusion\\.',
wordpress: '^@wordpress/',
};
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/deno/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/datasource/go/releases-goproxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ export class GoProxyDatasource extends Datasource {
},
asterisk: {
match: '*',
value: (_: string) => '[^\\/]*',
value: (_: string) => '[^/]*',
},
qmark: {
match: '?',
value: (_: string) => '[^\\/]',
value: (_: string) => '[^/]',
},
characterRangeOpen: {
match: '[',
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/hermit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/maven/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);

Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/pypi/common.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/bazelisk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GithubReleasesDatasource } from '../../datasource/github-releases';
export { extractPackageFile } from './extract';

export const defaultConfig = {
fileMatch: ['(^|\\/)\\.bazelversion$'],
fileMatch: ['(^|/)\\.bazelversion$'],
pinDigests: false,
};

Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/cocoapods/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { PackageDependency, PackageFile } 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*$`
),
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/flux/common.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/fvm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
4 changes: 2 additions & 2 deletions lib/modules/manager/github-actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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$',
],
};

Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/gitlabci/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>.+)`
);

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/modules/manager/gradle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/mint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export { extractPackageFile } from './extract';
export const supportedDatasources = [GitTagsDatasource.id];

export const defaultConfig = {
fileMatch: ['(^|\\/)Mintfile$'],
fileMatch: ['(^|/)Mintfile$'],
};
2 changes: 1 addition & 1 deletion lib/modules/manager/nix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/nuget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const defaultConfig = {
fileMatch: [
'\\.(?:cs|fs|vb)proj$',
'\\.(?:props|targets)$',
'(^|\\/)dotnet-tools\\.json$',
'(^|\\/)global\\.json$',
'(^|/)dotnet-tools\\.json$',
'(^|/)global\\.json$',
],
};

Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/pre-commit/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/puppet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export { extractPackageFile } from './extract';
export const language: ProgrammingLanguage = 'ruby';

export const defaultConfig = {
fileMatch: ['(^|\\/)Puppetfile$'],
fileMatch: ['(^|/)Puppetfile$'],
};

export const supportedDatasources = [
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/regex/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}",
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/terraform/lockfile/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/terraform/lockfile/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>".*)$`
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/woodpecker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
2 changes: 1 addition & 1 deletion lib/modules/versioning/kubernetes-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions lib/util/modules.ts
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/repository/update/pr/changelog/release-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ export function massageBody(
body = body.replace(regEx(/^<a name="[^"]*"><\/a>\n/), '');
body = body.replace(
regEx(
`^##? \\[[^\\]]*\\]\\(${baseUrl}[^/]*\\/[^/]*\\/compare\\/.*?\\n`,
`^##? \\[[^\\]]*\\]\\(${baseUrl}[^/]*/[^/]*/compare/.*?\\n`,
undefined,
false
),
''
);
// 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
Expand Down

0 comments on commit fdeba67

Please sign in to comment.