fix(apps): 대소문자·끝 슬래시만 다른 기능 라우트도 같은 경로로 거절한다 (1103/08-04)

문제
같은 모양 검사가 파라미터 이름만 지운 문자열로 비교했다. React Router는
대소문자를 무시하고 끝 슬래시를 같은 경로로 본다. 그래서 /shop/items/:itemId와
/shop/Items/:id, /shop/items와 /shop/items/가 조립을 통과했고 라우터는 그중
하나만 그렸다. 메뉴·레지스트리에는 둘 다 나왔다.

고른 방법
모양 키를 만들 때 소문자로 바꾸고 끝 슬래시를 지운다. 라우트 경로 문법을
소문자·끝 슬래시 없음으로 제한하는 검사는 기존 라우트에 새 규칙을 거는
것이라 버렸다.

위험·한계
라우터가 caseSensitive를 켜면 이 검사가 과하게 거절한다. src에 caseSensitive
사용은 없다.

검증
- RED: context-route-roots.test.ts의 새 두 행이 수정 전 실패.
- tests/architecture, router, context-layouts → 9 files / 64 tests 통과.
  /a/new와 /a/:id 허용 행은 그대로 통과. eslint 통과.

Refs: docs/reviews/2026-11-03-maturity-review/08-presentation.md 08-04
This commit is contained in:
DongHyeonka
2026-11-04 20:19:07 +09:00
parent 4282a541d0
commit 851fdedbcd
2 changed files with 34 additions and 2 deletions
+7 -2
View File
@@ -112,8 +112,13 @@ function assertFeatureRoutesReachOwningContext(
`A feature replaces a platform route only by declaring its id (${FEATURE_REPLACEABLE_PLATFORM_ROUTE_IDS.join(", ")}).`,
);
}
// Parameter names do not change how the router ranks a path.
const shape = path.replace(/:[^/]+/g, ":");
// Parameter names do not change how the router ranks a path, and
// (1103/08-04) neither do letter case or a trailing slash: the router
// matches case-insensitively and ignores the slash.
const shape = path
.replace(/:[^/]+/g, ":")
.toLowerCase()
.replace(/\/+$/, "");
const earlier = claimed.get(shape);
if (earlier !== undefined) {
throw new TypeError(
@@ -223,6 +223,33 @@ describe("feature routes and platform routes", () => {
).toThrow(/ITEM_DETAIL.*\/shop\/items\/:itemId.*items.*ORDER_DETAIL.*orders/);
});
it.each<
Readonly<{
differ: string;
first: Readonly<Record<string, string>>;
second: Readonly<Record<string, string>>;
}>
>([
{
differ: "only by letter case",
first: { ITEM_DETAIL: "/shop/items/:itemId" },
second: { OTHER_ITEM_DETAIL: "/shop/Items/:id" },
},
{
differ: "only by a trailing slash",
first: { ITEM_LIST: "/shop/items" },
second: { OTHER_ITEM_LIST: "/shop/items/" },
},
])("rejects two feature routes whose paths differ $differ", ({ first, second }) => {
// 1103/08-04. The router matches paths case-insensitively and ignores a
// trailing slash, so these tie like identical paths.
expect(() =>
app(
context("shop", "shop/*", [feature("items", first), feature("others", second)]),
),
).toThrow(/OTHER_ITEM_.*others.*has the same path as route ITEM_.*items/);
});
it("accepts a static path next to a parameter at the same depth", () => {
expect(() =>
app(