Skip to content

Commit

Permalink
Decode slug before trying to find matches
Browse files Browse the repository at this point in the history
  • Loading branch information
joas8211 committed May 7, 2023
1 parent ccf3847 commit 5d19e4e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/middleware/pathMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const createPathMapping =

// There must be a path with at least one segment and that segment is tenant
// slug.
const tenantSlug = req.url.slice(1).split("/")[0];
if (!tenantSlug) {
const encodedTenantSlug = req.url.slice(1).split("/")[0];
if (!encodedTenantSlug) {
res.status(404).send();
return;
}
Expand All @@ -45,7 +45,7 @@ export const createPathMapping =
req.tenant = (
await payload.find({
collection: options.tenantCollection,
where: { slug: { equals: tenantSlug } },
where: { slug: { equals: decodeURIComponent(encodedTenantSlug) } },
})
).docs[0];
if (!req.tenant) {
Expand All @@ -55,6 +55,6 @@ export const createPathMapping =

// Remove tenant slug from the request URL so it can be processed normally
// by payload.
req.url = req.url.slice(`/${tenantSlug}`.length);
req.url = req.url.slice(`/${encodedTenantSlug}`.length);
next();
};

0 comments on commit 5d19e4e

Please sign in to comment.