Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/fast-suits-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-ws": patch
---

Escape dist path for safe require() usage
2 changes: 1 addition & 1 deletion src/patches/helpers/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function getDistDirname() {
const nextWsPackagePath = //
require.resolve('next-ws/package.json', resolveOptions);
const nextWsDirName = resolveDirname(nextWsPackagePath);
return `${nextWsDirName.replaceAll('\\', '/')}/dist`;
return `${nextWsDirName}/dist`.replace(/\\/g, '/').replace(/'/g, "\\'");
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/server/helpers/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function createRouteRegex(routePattern: string) {
*/
function getRouteParams(routePattern: string, routePath: string) {
const routeRegex = createRouteRegex(routePattern);
const match = routePath.match(routeRegex);
const match = routePath.replace(/\/+$/, '').match(routeRegex);
if (!match) return null;
if (!match.groups) return {};

Expand Down Expand Up @@ -58,13 +58,13 @@ export function resolvePathToRoute(
...nextServer.getAppPathRoutes(),
};

let pathToRoute = null;
for (const [routePath, [filePath]] of Object.entries(routes)) {
const realPath = `${basePath}${routePath}`;
const routeParams = getRouteParams(realPath, requestPath);
if (routeParams) return { filePath: filePath!, routeParams };
if (routeParams) pathToRoute = { filePath: filePath!, routeParams };
}

return null;
return pathToRoute || null;
}

/**
Expand Down