Skip to content

Commit

Permalink
refactor: flagged relevant regex (#12976)
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh committed Dec 6, 2021
1 parent f0be5ee commit 597da6f
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 12 deletions.
4 changes: 3 additions & 1 deletion lib/datasource/npm/npmrc.ts
Expand Up @@ -9,6 +9,7 @@ import type { OutgoingHttpHeaders } from '../../util/http/types';
import { maskToken } from '../../util/mask';
import { regEx } from '../../util/regex';
import { add } from '../../util/sanitize';
import { ensureTrailingSlash } from '../../util/url';
import type { Npmrc, PackageResolution } from './types';

let npmrc: Record<string, any> = {};
Expand Down Expand Up @@ -112,7 +113,8 @@ export function resolvePackage(packageName: string): PackageResolution {
!authInfo &&
npmrc &&
npmrc._authToken &&
registryUrl.replace(/\/?$/, '/') === npmrc.registry?.replace(/\/?$/, '/') // TODO #12070
ensureTrailingSlash(registryUrl) ===
ensureTrailingSlash(npmrc?.registry || '')
) {
authInfo = { type: 'Bearer', token: npmrc._authToken };
}
Expand Down
3 changes: 2 additions & 1 deletion lib/datasource/packagist/index.ts
Expand Up @@ -7,6 +7,7 @@ import * as packageCache from '../../util/cache/package';
import * as hostRules from '../../util/host-rules';
import { Http, HttpOptions } from '../../util/http';
import { regEx } from '../../util/regex';
import { ensureTrailingSlash } from '../../util/url';
import * as composerVersioning from '../../versioning/composer';
import type { GetReleasesConfig, ReleaseResult } from '../types';
import type {
Expand Down Expand Up @@ -39,7 +40,7 @@ function getHostOpts(url: string): HttpOptions {
}

async function getRegistryMeta(regUrl: string): Promise<RegistryMeta | null> {
const url = URL.resolve(regUrl.replace(/\/?$/, '/'), 'packages.json'); // TODO #12070
const url = URL.resolve(ensureTrailingSlash(regUrl), 'packages.json');
const opts = getHostOpts(url);
const res = (await http.getJson<PackageMeta>(url, opts)).body;
const meta: RegistryMeta = {
Expand Down
3 changes: 1 addition & 2 deletions lib/datasource/sbt-package/index.ts
@@ -1,6 +1,7 @@
import { XmlDocument } from 'xmldoc';
import { logger } from '../../logger';
import { regEx } from '../../util/regex';
import { ensureTrailingSlash } from '../../util/url';
import * as ivyVersioning from '../../versioning/ivy';
import { compare } from '../../versioning/maven/compare';
import { MAVEN_REPO } from '../maven/common';
Expand All @@ -14,8 +15,6 @@ export const defaultRegistryUrls = [MAVEN_REPO];
export const defaultVersioning = ivyVersioning.id;
export const registryStrategy = 'hunt';

const ensureTrailingSlash = (str: string): string => str.replace(/\/?$/, '/'); // TODO #12070

export async function getArtifactSubdirs(
searchRoot: string,
artifact: string,
Expand Down
4 changes: 2 additions & 2 deletions lib/manager/dockerfile/extract.ts
Expand Up @@ -153,7 +153,7 @@ export function extractPackageFile(content: string): PackageFile | null {
const stageNames: string[] = [];

const fromMatches = content.matchAll(
/^[ \t]*FROM(?:\\\r?\n| |\t|#.*?\r?\n|[ \t]--[a-z]+=\S+?)*[ \t](?<image>\S+)(?:(?:\\\r?\n| |\t|#.*\r?\n)+as[ \t]+(?<name>\S+))?/gim // TODO #12070 complex for re2 has too many not supported groups
/^[ \t]*FROM(?:\\\r?\n| |\t|#.*?\r?\n|[ \t]--[a-z]+=\S+?)*[ \t](?<image>\S+)(?:(?:\\\r?\n| |\t|#.*\r?\n)+as[ \t]+(?<name>\S+))?/gim // TODO #12875 complex for re2 has too many not supported groups
);

for (const fromMatch of fromMatches) {
Expand All @@ -180,7 +180,7 @@ export function extractPackageFile(content: string): PackageFile | null {
}

const copyFromMatches = content.matchAll(
/^[ \t]*COPY(?:\\\r?\n| |\t|#.*\r?\n|[ \t]--[a-z]+=\w+?)*[ \t]--from=(?<image>\S+)/gim // TODO #12070 complex for re2 has too many not supported groups
/^[ \t]*COPY(?:\\\r?\n| |\t|#.*\r?\n|[ \t]--[a-z]+=\w+?)*[ \t]--from=(?<image>\S+)/gim // TODO #12875 complex for re2 has too many not supported groups
);

for (const copyFromMatch of copyFromMatches) {
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/npm/extract/index.ts
Expand Up @@ -108,7 +108,7 @@ export async function extractPackageFile(
} else {
npmrc = config.npmrc || '';
if (npmrc.length) {
npmrc = npmrc.replace(/\n?$/, '\n'); // TODO #12070 add \n to front when used with re2
npmrc = npmrc.replace(/\n?$/, '\n'); // TODO #12875 add \n to front when used with re2
}
if (repoNpmrc?.includes('package-lock')) {
logger.debug('Stripping package-lock setting from .npmrc');
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/npm/extract/pnpm.ts
Expand Up @@ -105,7 +105,7 @@ export async function detectPnpmWorkspaces(
packageFilters !== null &&
matchesAnyPattern(
packageFile,
packageFilters.map((filter) => filter.replace(/\/?$/, '/package.json')) // TODO #12070
packageFilters.map((filter) => filter.replace(/\/?$/, '/package.json')) // TODO #12875
);
if (isPackageInWorkspace) {
p.pnpmShrinkwrap = lockFilePath;
Expand Down
2 changes: 1 addition & 1 deletion lib/util/emoji.ts
Expand Up @@ -55,7 +55,7 @@ export function emojify(text: string): string {
const emojiRegexSrc = [emojibaseEmojiRegex, mathiasBynensEmojiRegex()].map(
({ source }) => source
);
const emojiRegex = new RegExp(`(?:${emojiRegexSrc.join('|')})`, 'g'); // TODO #12070 cannot figure it out
const emojiRegex = new RegExp(`(?:${emojiRegexSrc.join('|')})`, 'g'); // TODO #12875 cannot figure it out
const excludedModifiers = new Set([
'20E3',
'200D',
Expand Down
2 changes: 1 addition & 1 deletion lib/util/http/gitea.ts
Expand Up @@ -4,7 +4,7 @@ import { Http, HttpOptions, HttpResponse, InternalHttpOptions } from '.';

let baseUrl: string;
export const setBaseUrl = (newBaseUrl: string): void => {
baseUrl = newBaseUrl.replace(/\/*$/, '/'); // TODO #12070
baseUrl = newBaseUrl.replace(/\/*$/, '/'); // TODO #12875
};

export interface GiteaHttpOptions extends InternalHttpOptions {
Expand Down
2 changes: 1 addition & 1 deletion lib/util/url.ts
Expand Up @@ -15,7 +15,7 @@ export function ensurePathPrefix(url: string, prefix: string): string {
}

export function ensureTrailingSlash(url: string): string {
return url.replace(/\/?$/, '/'); // TODO #12070 adds slash at the front when re2 is used
return url.replace(/\/?$/, '/'); // TODO #12875 adds slash at the front when re2 is used
}

export function trimTrailingSlash(url: string): string {
Expand Down
2 changes: 1 addition & 1 deletion lib/versioning/ruby/index.ts
Expand Up @@ -136,7 +136,7 @@ const getNewValue = ({
)
.map(
(element) =>
element.replace(/(?<whitespace>\s*)$/, `${delimiter}$<whitespace>`) // TODO #12071 #12070 adds ' at front when re2 is used
element.replace(/(?<whitespace>\s*)$/, `${delimiter}$<whitespace>`) // TODO #12071 #12875 adds ' at front when re2 is used
)
.join(',');
}
Expand Down

0 comments on commit 597da6f

Please sign in to comment.