Skip to content

Commit 6004141

Browse files
authored
fix(core): match * glob in routes (#574)
Fixes #569
1 parent d24df7a commit 6004141

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/core/utils/glob.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe("glob functions", () => {
1515
});
1616

1717
it("glob = *", () => {
18-
expect(globToRegExp("*")).toBe("*");
18+
expect(globToRegExp("*")).toBe(".*");
1919
});
2020
it("glob = /*", () => {
2121
expect(globToRegExp("/*")).toBe("\\/.*");

src/core/utils/glob.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export function globToRegExp(glob: string | undefined) {
1616
return "";
1717
}
1818

19+
if (glob === "*") {
20+
logger.silly(` - glob is ${chalk.yellow("*")}, return ${chalk.yellow(".*")}`);
21+
return ".*";
22+
}
23+
1924
const filesExtensionMatch = glob.match(/{.*}/);
2025
if (filesExtensionMatch) {
2126
const filesExtensionExpression = filesExtensionMatch[0];

src/msha/routes-engine/route-processor.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,23 @@ function doesRequestPathMatchWildcardRoute(requestPath: string, requestPathFileW
110110
return false;
111111
}
112112

113-
// we don't support full globs in the config file.
114-
// add this little utility to convert a wildcard into a valid glob pattern
115-
const regexp = new RegExp(`^${globToRegExp(requestPathFileWithWildcard)}$`);
116-
logger.silly(` - regexp: ${chalk.yellow(regexp)}`);
117-
118-
const isMatch = regexp.test(requestPath);
119-
logger.silly(` - isMatch: ${chalk.yellow(isMatch)}`);
120-
121-
return isMatch;
113+
try {
114+
logger.silly(` - route regexp: ${chalk.yellow(requestPathFileWithWildcard)}`);
115+
// we don't support full globs in the config file.
116+
// add this little utility to convert a wildcard into a valid glob pattern
117+
const regexp = new RegExp(`^${globToRegExp(requestPathFileWithWildcard)}$`);
118+
logger.silly(` - regexp: ${chalk.yellow(regexp)}`);
119+
120+
const isMatch = regexp.test(requestPath);
121+
logger.silly(` - isMatch: ${chalk.yellow(isMatch)}`);
122+
123+
return isMatch;
124+
} catch (error) {
125+
logger.silly(` - ERROR: IGNORING REGEXP!!!`);
126+
logger.silly(` - read: ${chalk.yellow("https://learn.microsoft.com/en-us/azure/static-web-apps/configuration#wildcards")}`);
127+
logger.silly(` - error: ${chalk.yellow(error)}`);
128+
return false;
129+
}
122130
}
123131

124132
export function isCustomUrl(req: http.IncomingMessage) {

0 commit comments

Comments
 (0)