fix: allow whitelisted paths like onboarding as team/user slugs on org domains (#24984)
* fix: allow whitelisted paths like onboarding as team/user slugs on org domains - Add whitelistedPaths array to pagesAndRewritePaths.js with 'onboarding' - Update getRegExpMatchingAllReservedRoutes to accept exclusions parameter - Modify org route patterns to exclude whitelisted paths from reserved routes - Add tests to verify onboarding can be used as a slug on org domains - Fixes issue where acme.cal.com/onboarding would 404 This allows teams/users on org domains to use 'onboarding' as their slug while still preserving the /onboarding app route on non-org domains. Co-Authored-By: [email protected] <[email protected]> * Remove accidental change by AI * Add special character handling test --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
528b27f31e
commit
06e5c9803a
4 files changed
+125
-17
No files matched your search
@@ -2,7 +2,7 @@ import { it, expect, describe, beforeAll } from "vitest";
|
||||
|
||||
import { getRegExpThatMatchesAllOrgDomains } from "../../getNextjsOrgRewriteConfig";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
/* eslint-disable @typescript-eslint/no-require-imports */
|
||||
const { match, pathToRegexp } = require("next/dist/compiled/path-to-regexp");
|
||||
type MatcherRes = (path: string) => { params: Record<string, string> };
|
||||
let orgUserTypeRouteMatch: MatcherRes;
|
||||
@@ -15,7 +15,6 @@ beforeAll(async () => {
|
||||
const {
|
||||
orgUserRoutePath,
|
||||
orgUserTypeRoutePath,
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
} = require("../../pagesAndRewritePaths");
|
||||
|
||||
orgUserTypeRouteMatch = match(orgUserTypeRoutePath);
|
||||
@@ -162,5 +161,80 @@ describe("next.config.js - Org Rewrite", () => {
|
||||
expect(orgUserRouteMatch("/forms/xdsdf-sd")).toEqual(false);
|
||||
expect(orgUserRouteMatch("/router?form=")).toEqual(false);
|
||||
});
|
||||
|
||||
it("Whitelisted routes should match on org domains", () => {
|
||||
expect(orgUserRouteMatch("/onboarding")?.params).toEqual({
|
||||
user: "onboarding",
|
||||
});
|
||||
expect(orgUserTypeRouteMatch("/onboarding/30min")?.params).toEqual({
|
||||
user: "onboarding",
|
||||
type: "30min",
|
||||
});
|
||||
});
|
||||
|
||||
describe("Character validation in org slugs", () => {
|
||||
it("should allow valid characters: alphanumeric, hyphens, and underscores", () => {
|
||||
// Valid usernames with allowed characters
|
||||
expect(orgUserRouteMatch("/john-doe")?.params).toEqual({
|
||||
user: "john-doe",
|
||||
});
|
||||
expect(orgUserRouteMatch("/john_doe")?.params).toEqual({
|
||||
user: "john_doe",
|
||||
});
|
||||
expect(orgUserRouteMatch("/user123")?.params).toEqual({
|
||||
user: "user123",
|
||||
});
|
||||
expect(orgUserRouteMatch("/ABC-123_xyz")?.params).toEqual({
|
||||
user: "ABC-123_xyz",
|
||||
});
|
||||
});
|
||||
|
||||
it("should reject invalid punctuation characters in org slugs", () => {
|
||||
// These should NOT match because they contain invalid characters
|
||||
// The character class [a-zA-Z0-9-_] when hyphen is unescaped between 9 and _
|
||||
// creates a range from - (ASCII 45) to _ (ASCII 95), which includes : ; < = > ? @ [ \ ] ^
|
||||
|
||||
// Colon (:) - ASCII 58
|
||||
expect(orgUserRouteMatch("/user:name")).toEqual(false);
|
||||
|
||||
// Semicolon (;) - ASCII 59
|
||||
expect(orgUserRouteMatch("/user;name")).toEqual(false);
|
||||
|
||||
// Less than (<) - ASCII 60
|
||||
expect(orgUserRouteMatch("/user<name")).toEqual(false);
|
||||
|
||||
// Equals (=) - ASCII 61
|
||||
expect(orgUserRouteMatch("/user=name")).toEqual(false);
|
||||
|
||||
// Greater than (>) - ASCII 62
|
||||
expect(orgUserRouteMatch("/user>name")).toEqual(false);
|
||||
|
||||
// Question mark (?) - ASCII 63
|
||||
expect(orgUserRouteMatch("/user?name")).toEqual(false);
|
||||
|
||||
// At symbol (@) - ASCII 64
|
||||
expect(orgUserRouteMatch("/user@name")).toEqual(false);
|
||||
|
||||
// Square brackets ([, ]) - ASCII 91, 93
|
||||
expect(orgUserRouteMatch("/user[name")).toEqual(false);
|
||||
expect(orgUserRouteMatch("/user]name")).toEqual(false);
|
||||
|
||||
// Backslash (\) - ASCII 92
|
||||
expect(orgUserRouteMatch("/user\\name")).toEqual(false);
|
||||
|
||||
// Caret (^) - ASCII 94
|
||||
expect(orgUserRouteMatch("/user^name")).toEqual(false);
|
||||
|
||||
// Other common punctuation that should also be rejected
|
||||
expect(orgUserRouteMatch("/user.name")).toEqual(false);
|
||||
expect(orgUserRouteMatch("/user!name")).toEqual(false);
|
||||
expect(orgUserRouteMatch("/user#name")).toEqual(false);
|
||||
expect(orgUserRouteMatch("/user$name")).toEqual(false);
|
||||
expect(orgUserRouteMatch("/user%name")).toEqual(false);
|
||||
expect(orgUserRouteMatch("/user&name")).toEqual(false);
|
||||
expect(orgUserRouteMatch("/user*name")).toEqual(false);
|
||||
expect(orgUserRouteMatch("/user+name")).toEqual(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,10 +1,10 @@
|
||||
import { it, expect, describe } from "vitest";
|
||||
|
||||
import { pages } from "../../pagesAndRewritePaths.js";
|
||||
import { topLevelRoutesExcludedFromOrgRewrite, topLevelRouteNamesWhitelistedForRewrite } from "../../pagesAndRewritePaths.js";
|
||||
|
||||
describe("pagesAndRewritePaths", () => {
|
||||
describe("beforeFiles must exclude routes in pages/app router", () => {
|
||||
const BEFORE_REWRITE_EXCLUDE_PAGES = [
|
||||
describe("beforeFiles must exclude top-level routes in pages/app router", () => {
|
||||
const ROUTES_EXCLUDED_FROM_ORG_REWRITE = [
|
||||
"apps",
|
||||
"availability",
|
||||
"booking",
|
||||
@@ -30,12 +30,18 @@ describe("pagesAndRewritePaths", () => {
|
||||
"routing-forms",
|
||||
"signup",
|
||||
"team",
|
||||
"d",
|
||||
"d"
|
||||
];
|
||||
|
||||
it("should include all required routes", () => {
|
||||
BEFORE_REWRITE_EXCLUDE_PAGES.forEach((route) => {
|
||||
expect(pages).toContain(route);
|
||||
it("should include all required top-level route names", () => {
|
||||
ROUTES_EXCLUDED_FROM_ORG_REWRITE.forEach((route) => {
|
||||
expect(topLevelRoutesExcludedFromOrgRewrite).toContain(route);
|
||||
});
|
||||
});
|
||||
|
||||
it("should NOT include whitelisted routes", () => {
|
||||
topLevelRouteNamesWhitelistedForRewrite.forEach((route) => {
|
||||
expect(topLevelRoutesExcludedFromOrgRewrite).not.toContain(route);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user