From b42761dbd9a8d328249989d73130b4169b7cc2b5 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Sun, 21 Apr 2024 11:54:41 +0200 Subject: [PATCH] chore: Revert "chore(util/string-match): add massagePattern option" (#28555) --- lib/util/string-match.spec.ts | 18 ------------------ lib/util/string-match.ts | 27 +++------------------------ 2 files changed, 3 insertions(+), 42 deletions(-) diff --git a/lib/util/string-match.spec.ts b/lib/util/string-match.spec.ts index 4a6c7fbd2bdca2..0321d4ce5720d6 100644 --- a/lib/util/string-match.spec.ts +++ b/lib/util/string-match.spec.ts @@ -89,23 +89,5 @@ describe('util/string-match', () => { it('returns false if negative pattern is matched', () => { expect(matchRegexOrGlob('test', '!/te/')).toBeFalse(); }); - - it('returns true for wildcard is massaged', () => { - expect( - matchRegexOrGlob('test', '^*$', { massagePattern: true }), - ).toBeTrue(); - }); - - it('returns true for glob wildcard is massaged', () => { - expect( - matchRegexOrGlob('test', '*', { massagePattern: true }), - ).toBeTrue(); - }); - - it('returns true for massaged regex pattern is massaged', () => { - expect( - matchRegexOrGlob('test', '.*', { massagePattern: true }), - ).toBeTrue(); - }); }); }); diff --git a/lib/util/string-match.ts b/lib/util/string-match.ts index 1349e292d0004e..241debfbd17d0d 100644 --- a/lib/util/string-match.ts +++ b/lib/util/string-match.ts @@ -4,10 +4,6 @@ import { regEx } from './regex'; export type StringMatchPredicate = (s: string) => boolean; -export interface matchRegexOrGlobOptions { - massagePattern?: boolean; -} - export function isDockerDigest(input: string): boolean { return /^sha256:[a-f0-9]{64}$/i.test(input); } @@ -22,15 +18,7 @@ export function getRegexOrGlobPredicate(pattern: string): StringMatchPredicate { return (x: string): boolean => mm.match(x); } -export function matchRegexOrGlob( - input: string, - rawPattern: string, - options?: matchRegexOrGlobOptions, -): boolean { - const pattern = options?.massagePattern - ? massagePattern(rawPattern) - : rawPattern; - +export function matchRegexOrGlob(input: string, pattern: string): boolean { const predicate = getRegexOrGlobPredicate(pattern); return predicate(input); } @@ -38,7 +26,6 @@ export function matchRegexOrGlob( export function matchRegexOrGlobList( input: string, patterns: string[], - options?: matchRegexOrGlobOptions, ): boolean { if (!patterns.length) { return false; @@ -50,9 +37,7 @@ export function matchRegexOrGlobList( ); if ( positivePatterns.length && - !positivePatterns.some((pattern) => - matchRegexOrGlob(input, pattern, options), - ) + !positivePatterns.some((pattern) => matchRegexOrGlob(input, pattern)) ) { return false; } @@ -63,9 +48,7 @@ export function matchRegexOrGlobList( ); if ( negativePatterns.length && - !negativePatterns.every((pattern) => - matchRegexOrGlob(input, pattern, options), - ) + !negativePatterns.every((pattern) => matchRegexOrGlob(input, pattern)) ) { return false; } @@ -111,7 +94,3 @@ export function getRegexPredicate(input: string): StringMatchPredicate | null { } return null; } - -function massagePattern(pattern: string): string { - return pattern === '^*$' || pattern === '*' ? '**' : `/${pattern}/`; -}