Skip to content
Merged

2.4.1 #228

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/core/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export class Route<S extends DefaultState = DefaultState> {
}

get regexPath() {
return new RegExp(this.path);
const escaped = this.path.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
return new RegExp(escaped);
}

match(ctx: RequestContext<S>): boolean {
Expand Down
17 changes: 9 additions & 8 deletions lib/http/HttpRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ export class HttpRoute<
return x;
}

override get regexPath() {
const pattern = this.path.replace(
/:(\w+)/g,
(_, paramName) => `(?<${paramName}>[^/]+)`
);

return new RegExp(`^${pattern}/?$`);
}
override get regexPath() {
const escaped = this.path.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const pattern = escaped.replace(
/:(\w+)/g,
(_, paramName) => `(?<${paramName}>[^/]+)`
);

return new RegExp(`^${pattern}/?$`);
}

override match(ctx: RequestContext<S>): boolean {
const match = this.regexPath.exec(ctx.url.pathname);
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sejori/peko",
"version": "2.4.2",
"version": "2.4.1",
"description": "Featherweight apps on the edge 🐣⚡",
"main": "dist/mod.js",
"directories": {
Expand Down Expand Up @@ -30,7 +30,7 @@
"url": "git+https://github.com/sejori/peko.git"
},
"author": "Seb Ringrose <sebringrose@gmail.com>",
"license": "GPL-3.0",
"license": "MIT",
"bugs": {
"url": "https://github.com/sejori/peko/issues"
},
Expand Down