From 669b2d0b977f89338ca5348941b7b1763efc4d1b Mon Sep 17 00:00:00 2001 From: Aaron Powell Date: Tue, 2 Jan 2024 16:52:51 +1100 Subject: [PATCH 1/2] Failing test to demonstrate #792 --- src/core/utils/glob.spec.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/utils/glob.spec.ts b/src/core/utils/glob.spec.ts index 1381c2acd..19fbe9ad1 100644 --- a/src/core/utils/glob.spec.ts +++ b/src/core/utils/glob.spec.ts @@ -40,6 +40,10 @@ describe("glob functions", () => { it("glob = {foo,bar}.json", () => { expect(globToRegExp("{foo,bar}.json")).toBe("(foo|bar).json"); }); + + it("glob = /foo*", () => { + expect(globToRegExp("/foo*")).toBe("\\/foo.*"); + }); }); // describe isValidGlobExpression From 20f8b22297986e24f8f3e06fab74f50af973b422 Mon Sep 17 00:00:00 2001 From: Aaron Powell Date: Tue, 2 Jan 2024 17:00:36 +1100 Subject: [PATCH 2/2] Fixes #792 Improved the string replacement to generate the regex (such as leaving the . in for extensions) Updated tests to understand the new regex structure --- src/core/utils/glob.spec.ts | 8 ++++---- src/core/utils/glob.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/utils/glob.spec.ts b/src/core/utils/glob.spec.ts index 19fbe9ad1..beb806daf 100644 --- a/src/core/utils/glob.spec.ts +++ b/src/core/utils/glob.spec.ts @@ -26,19 +26,19 @@ describe("glob functions", () => { }); it("glob = /*.{ext}", () => { - expect(globToRegExp("/*.{ext}")).toBe("\\/.*(ext)"); + expect(globToRegExp("/*.{ext}")).toBe("\\/.*\\.(ext)"); }); it("glob = /*.{ext,gif}", () => { - expect(globToRegExp("/*.{ext,gif}")).toBe("\\/.*(ext|gif)"); + expect(globToRegExp("/*.{ext,gif}")).toBe("\\/.*\\.(ext|gif)"); }); it("glob = /foo/*.{ext,gif}", () => { - expect(globToRegExp("/foo/*.{ext,gif}")).toBe("\\/foo\\/.*(ext|gif)"); + expect(globToRegExp("/foo/*.{ext,gif}")).toBe("\\/foo\\/.*\\.(ext|gif)"); }); it("glob = {foo,bar}.json", () => { - expect(globToRegExp("{foo,bar}.json")).toBe("(foo|bar).json"); + expect(globToRegExp("{foo,bar}.json")).toBe("(foo|bar)\\.json"); }); it("glob = /foo*", () => { diff --git a/src/core/utils/glob.ts b/src/core/utils/glob.ts index 1c7105a00..fca6674b6 100644 --- a/src/core/utils/glob.ts +++ b/src/core/utils/glob.ts @@ -31,7 +31,7 @@ export function globToRegExp(glob: string | undefined) { } } - return glob.replace(/\//g, "\\/").replace("*.", ".*").replace("/*", "/.*"); + return glob.replace(/\//g, "\\/").replace(".", "\\.").replace("*", ".*"); } /**