Repository navigation
Description
A subject whose id contains /, #, ? or % cannot have any of its records opened, and its "View Current Subject" link goes nowhere. Two places paste the raw id into a URL path. Such ids are legal: a custom identifier only has to avoid $ (and match the group's optional regex), the upload's SUBJECT_ID_REGEX is /^[^$\s]+$/, and the group-name prefix only has spaces replaced. So 2024/001, P#12, or a group named Psychosis/PEPP all produce such ids.
subjectQueryOptionsrequests/v1/subjects/${params.id}. ForPEPP$2024/001that is/v1/subjects/PEPP$2024/001, which matches no API route (404).#truncates the path at the fragment, and%makes Express fail to decode the parameter. The record detail page's loader awaits this query, so every record of that subject opens to the error page.useNavItemsbuilds the session link as`/datahub/subjects/${currentSession?.subjectId}/table`and hands it tonavigate({ to }), so the router resolves the wrong path.
useSubjectDemographicsLookup already gets this right with encodeURIComponent(params.id).
Where
apps/web/src/hooks/useSubjectQuery.ts:12:
const response = await axios.get(`/v1/subjects/${params.id}`, { params });apps/web/src/hooks/useNavItems.ts:282:
url: `/datahub/subjects/${currentSession?.subjectId}/table`(The subject lookup in apps/web/src/routes/_app/datahub/subjects/index.tsx:317 has the same unencoded `/v1/subjects/${id}`.)
Reproduce
- Start a session with the custom identifier
2024/001and complete any instrument. - In the sidebar, click View Current Subject.
- Go to Data Hub → Subjects, open the subject, and click its record in the table.
Actual: step 2 lands on the not-found page. Step 3 requests GET /v1/subjects/<Group>$2024/001, gets a 404, and shows the error page.
Expected: both open the subject and the record.
Tests
apps/web/src/hooks/__tests__/useSubjectQuery.test.ts:it('should encode the subject id in the request path, so an id containing a slash or hash reaches the subject endpoint').apps/web/src/hooks/__tests__/useNavItems.test.ts:it('should link to the current subject through its encoded id').testing/src/specs/subject-detail.spec.ts: start a session with a custom id containing/, complete an instrument, and open the record from the subject table.
Suggested fix
Use encodeURIComponent(params.id) in subjectQueryOptions, and drop the stray { params }, which also sends the id as ?id=. In useNavItems, navigate with route params (to: '/datahub/subjects/$subjectId/table', params: { subjectId }) rather than an interpolated string, which means carrying params on NavItem. Otherwise encode the segment.
Activity
joshunrau commentedon Oct 7, 2026
Two more call sites break the same way. In the Data Hub subjects table, the row click handlers interpolate the raw id into a relative path:
apps/web/src/routes/_app/datahub/subjects/index.tsx:675and:678:The fix should cover these as well: navigate with typed route params (
to: '/datahub/subjects/$subjectId/table', params: { subjectId: subject.id }).joshunrau commentedon Oct 26, 2026
Still reproduces on
main(d86740e). None of the files involved has changed since the issue was filed.Two more call sites
apps/web/src/routes/_app/datahub/subjects/index.tsx:325: when the lookup at:317succeeds, it navigates to`./${response.data.id}/table`, so encoding the request alone is not enough.apps/web/src/routes/_app/datahub/subjects/$subjectId/route.tsx:18: the Table, Graph and Assignments tabs are built from the decodedparams.subjectId, so for2024/001they point at a path no route matches.The router also reads a raw id as template syntax. router-core parses a segment that starts with
$as a param, so in a group named$Lab(a legal name, see #1725) the row click at:675goes to/datahub/subjects/undefined/table.Tab highlighting is already wrong
A typed param is encoded with
encodeURIComponent, and router-core only appliesdecodeURItolocation.pathname(decodePath), so%24and%2Fstay encoded. Custom-ID subject ids always contain$, and their record page is opened through the typed./$recordIdnavigate ($subjectId/table/index.tsx:96,:101). Its URL holds%24whileTabLink.tsx:12runsstartsWithagainst a raw$, so no tab is highlighted there. #1807's instrument-hub links pass typed params too, so once it lands the table page loses its highlight as well.Plan
encodeURIComponentthe id atuseSubjectQuery.ts:12(dropping{ params }) and atsubjects/index.tsx:317.{ params: { subjectId }, to: '/datahub/subjects/$subjectId/table' }atsubjects/index.tsx:325,:675and:678.useNavItems.ts:282androute.tsx:18produce strings that are compared withlocation.pathname(Sidebar.tsx:58-59,Navbar.tsx:95-96,TabLink.tsx:12). Build them withuseRouter().buildLocation({ params: { subjectId }, to }).pathname, withto: '/datahub/subjects/$subjectId'for the tab base. That is exactly whatlocation.pathnameholds after the navigation, and passing it back as a plaintostring reaches the same subject.NavItem.urlstays astring, andNavButton,TabLinkand the walkthrough selectors (WalkthroughProvider.tsx:327,:344,:378,:397, which use the id123) need no change. PuttingparamsonNavItemwould mean rewriting those checks too. PlainencodeURIComponentroutes correctly but breaks highlighting for non-ASCII ids: for a group namedÉquipeit gives%C3%89quipe%24001, whilelocation.pathnameholdsÉquipe%24001.In step 3, there is no
subjectIdto pass when no session is active. Do not fall back to/datahub/subjectsfor the disabled item:disabled && location.pathname !== urlwould enable it on that page.Tests
These assert the current behaviour and have to change:
useSubjectQuery.test.ts:39(the{ params }argument),datahub/subjects/__tests__/index.test.tsx:184,:191and:428, and$subjectId/__tests__/route.test.tsx:64-84. The route test also mocks the pathname with a raw$(:14,:43,:73), which the router no longer produces once every link passes typed params. That test anduseNavItems.test.tsrender without a router, so they needuseRoutermocked.For e2e, the regex
/\/datahub\/subjects\/.+\/table$/atdatahub.spec.ts:168also matches a broken/path, so a/variant of the lookup test must assert thatsubject-tableis visible.getUrlWithParams(testing/src/pages/__root.page.ts:19-27) substitutes params without encoding, so drive the newsubject-detail.spec.tstest through the sidebar and the table rather thangoto. One custom id containing/,#,?and%covers every case.Related
TabLink.tsx,$subjectId/route.tsx,useNavItems.ts,datahub/subjects/index.tsx) but none of these lines, so either can land first. Only the line numbers move.AppFactory), not Express. find-my-way rejects a malformed%with a 400 and decodes:idonce.DELETE /v1/subjects/:id(apps/api/src/subjects/subjects.controller.ts:19) then runsdecodeURIComponenta second time, so an id containing%throws andA%41resolves to the subjectAA. No web code calls that endpoint. It needs its own API issue.Triage note written with Claude Code. Code references point at
main@d86740e.