Skip to content

Commit

Permalink
chore: Revert "chore(util/string-match): add massagePattern option" (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Apr 21, 2024
1 parent b2711f8 commit b42761d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 42 deletions.
18 changes: 0 additions & 18 deletions lib/util/string-match.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
27 changes: 3 additions & 24 deletions lib/util/string-match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -22,23 +18,14 @@ 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);
}

export function matchRegexOrGlobList(
input: string,
patterns: string[],
options?: matchRegexOrGlobOptions,
): boolean {
if (!patterns.length) {
return false;
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -111,7 +94,3 @@ export function getRegexPredicate(input: string): StringMatchPredicate | null {
}
return null;
}

function massagePattern(pattern: string): string {
return pattern === '^*$' || pattern === '*' ? '**' : `/${pattern}/`;
}

0 comments on commit b42761d

Please sign in to comment.