Skip to content

Commit

Permalink
Fixes Azure#792
Browse files Browse the repository at this point in the history
Improved the string replacement to generate the regex (such as leaving the . in for extensions)
Updated tests to understand the new regex structure
  • Loading branch information
aaronpowell committed Jan 2, 2024
1 parent 669b2d0 commit 20f8b22
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/core/utils/glob.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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*", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function globToRegExp(glob: string | undefined) {
}
}

return glob.replace(/\//g, "\\/").replace("*.", ".*").replace("/*", "/.*");
return glob.replace(/\//g, "\\/").replace(".", "\\.").replace("*", ".*");
}

/**
Expand Down

0 comments on commit 20f8b22

Please sign in to comment.