Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(deliverables): open latest-version links for file names with spaces or non-ASCII characters (#10271)
pseudoyu1643073b19ca
diff --git a/apps/web/app/[workspaceSlug]/(dashboard)/issues/[id]/deliverables/[name]/page.test.tsx b/apps/web/app/[workspaceSlug]/(dashboard)/issues/[id]/deliverables/[name]/page.test.tsxindex 90297061a1..8c71eb5bdd 100644--- a/apps/web/app/[workspaceSlug]/(dashboard)/issues/[id]/deliverables/[name]/page.test.tsx+++ b/apps/web/app/[workspaceSlug]/(dashboard)/issues/[id]/deliverables/[name]/page.test.tsx@@ -3,6 +3,7 @@ import { act, render } from "@testing-library/react";import { beforeEach, describe, expect, it, vi } from "vitest";import { getRouteRegex } from "next/dist/shared/lib/router/utils/route-regex";import { getRouteMatcher } from "next/dist/shared/lib/router/utils/route-matcher";+import { getDynamicParam } from "next/dist/shared/lib/router/utils/get-dynamic-param";import { paths } from "@multica/core/paths";const routeProps = vi.hoisted(() => ({@@ -18,22 +19,27 @@ vi.mock("@multica/views/issues/components", () => ({import IssueDeliverablePage from "./page";-// Next's own matcher for this route, so the params below are the ones the-// page really receives.+// Next's own matcher for this route, then the step the App Router runs on+// each matched value before a page sees it, so the params below are the ones+// the page really receives: the matcher decodes the segment and+// `getDynamicParam` percent-encodes it again.const matchRoute = getRouteMatcher(getRouteRegex("/[workspaceSlug]/issues/[id]/deliverables/[name]"),);+function pageParam(matched: Parameters<typeof getDynamicParam>[0], key: string): string {+ return getDynamicParam(matched, key, "d", null, null).value as string;+}+async function renderLink(filename: string) {const href = paths.workspace("acme").issueDeliverable("MUL-1", filename);- const params = matchRoute(href);- if (!params) throw new Error(`route did not match ${href}`);+ const matched = matchRoute(href);+ if (!matched) throw new Error(`route did not match ${href}`);+ const params = { id: pageParam(matched, "id"), name: pageParam(matched, "name") };await act(async () => {render(<Suspense fallback={null}>- <IssueDeliverablePage- params={Promise.resolve(params as { id: string; name: string })}- />+ <IssueDeliverablePage params={Promise.resolve(params)} /></Suspense>,);});@@ -49,8 +55,9 @@ describe("deliverable link page", () => {"report.html","调研 报告.html","Q3 调研/报告 #2?.html",- // Literal percent escapes in the file name: Next has already decoded the- // segment once, and a second decode would name a different file.+ "レポート 最終.html",+ // Literal percent escapes in the file name: exactly one decode gives the+ // name back, a second would name a different file."report%20final.html","report%25final.html","100%.html",diff --git a/apps/web/app/[workspaceSlug]/(dashboard)/issues/[id]/deliverables/[name]/page.tsx b/apps/web/app/[workspaceSlug]/(dashboard)/issues/[id]/deliverables/[name]/page.tsxindex 7dff81822b..d549e0fc64 100644--- a/apps/web/app/[workspaceSlug]/(dashboard)/issues/[id]/deliverables/[name]/page.tsx+++ b/apps/web/app/[workspaceSlug]/(dashboard)/issues/[id]/deliverables/[name]/page.tsx@@ -7,9 +7,12 @@ import { ErrorBoundary } from "@multica/ui/components/common/error-boundary";// `/{ws}/issues/{id}/deliverables/{name}`: the issue page, opened on the// newest version of the deliverable called `name`.//-// Next hands dynamic params over already decoded, so `name` is the file name-// itself. Decoding it again would turn a literal `report%20final.html` into-// `report final.html` and look up the wrong file.+// The App Router hands a dynamic param over percent-encoded: it decodes the+// matched segment and runs `encodeURIComponent` on it again, so a file called+// `調査 報告.html` arrives as `%E8%AA%BF...%20...html`. One decode gives the+// file name back and, because the value is always `encodeURIComponent`+// output, cannot throw. Exactly one: a second would turn a literal+// `report%20final.html` into `report final.html` and look up the wrong file.export default function IssueDeliverablePage({params,}: {@@ -18,7 +21,7 @@ export default function IssueDeliverablePage({const { id, name } = use(params);return (<ErrorBoundary resetKeys={[id]}>- <IssueDetailRoute routeId={id} deliverable={name} />+ <IssueDetailRoute routeId={id} deliverable={decodeURIComponent(name)} /></ErrorBoundary>);}