fix: remove manual encodeURIComponent from pathUtils (react-router v7 encodes automatically)

react-router v7's generatePath() now calls encodeURIComponent() on all
path params. pathUtils.ts was also calling encodeURIComponent() before
passing to generatePath, resulting in double-encoding (e.g. '#' became
'%2523' instead of '%23').

This caused spaces/rooms with alias paths to receive double-encoded
room IDs from useParams(), which were then re-encoded by matrix-sdk
when making HTTP requests (400 Bad Request from Synapse).

Remove the manual encodeURIComponent() calls -- generatePath handles it.
This commit is contained in:
Lotus Bot
2026-05-22 01:59:00 -04:00
parent 7168b11323
commit a5e5b3c413
+14 -14
View File
@@ -73,17 +73,17 @@ export const getAppPathFromHref = (baseUrl: string, href: string): string => {
export const getRootPath = (): string => ROOT_PATH; export const getRootPath = (): string => ROOT_PATH;
export const getLoginPath = (server?: string): string => { export const getLoginPath = (server?: string): string => {
const params = server ? { server: encodeURIComponent(server) } : undefined; const params = server ? { server } : undefined;
return generatePath(LOGIN_PATH, params); return generatePath(LOGIN_PATH, params);
}; };
export const getRegisterPath = (server?: string): string => { export const getRegisterPath = (server?: string): string => {
const params = server ? { server: encodeURIComponent(server) } : undefined; const params = server ? { server } : undefined;
return generatePath(REGISTER_PATH, params); return generatePath(REGISTER_PATH, params);
}; };
export const getResetPasswordPath = (server?: string): string => { export const getResetPasswordPath = (server?: string): string => {
const params = server ? { server: encodeURIComponent(server) } : undefined; const params = server ? { server } : undefined;
return generatePath(RESET_PASSWORD_PATH, params); return generatePath(RESET_PASSWORD_PATH, params);
}; };
@@ -93,8 +93,8 @@ export const getHomeJoinPath = (): string => HOME_JOIN_PATH;
export const getHomeSearchPath = (): string => HOME_SEARCH_PATH; export const getHomeSearchPath = (): string => HOME_SEARCH_PATH;
export const getHomeRoomPath = (roomIdOrAlias: string, eventId?: string): string => { export const getHomeRoomPath = (roomIdOrAlias: string, eventId?: string): string => {
const params = { const params = {
roomIdOrAlias: encodeURIComponent(roomIdOrAlias), roomIdOrAlias,
eventId: eventId ? encodeURIComponent(eventId) : null, eventId: eventId ?? null,
}; };
return generatePath(HOME_ROOM_PATH, params); return generatePath(HOME_ROOM_PATH, params);
@@ -104,8 +104,8 @@ export const getDirectPath = (): string => DIRECT_PATH;
export const getDirectCreatePath = (): string => DIRECT_CREATE_PATH; export const getDirectCreatePath = (): string => DIRECT_CREATE_PATH;
export const getDirectRoomPath = (roomIdOrAlias: string, eventId?: string): string => { export const getDirectRoomPath = (roomIdOrAlias: string, eventId?: string): string => {
const params = { const params = {
roomIdOrAlias: encodeURIComponent(roomIdOrAlias), roomIdOrAlias,
eventId: eventId ? encodeURIComponent(eventId) : null, eventId: eventId ?? null,
}; };
return generatePath(DIRECT_ROOM_PATH, params); return generatePath(DIRECT_ROOM_PATH, params);
@@ -113,20 +113,20 @@ export const getDirectRoomPath = (roomIdOrAlias: string, eventId?: string): stri
export const getSpacePath = (spaceIdOrAlias: string): string => { export const getSpacePath = (spaceIdOrAlias: string): string => {
const params = { const params = {
spaceIdOrAlias: encodeURIComponent(spaceIdOrAlias), spaceIdOrAlias,
}; };
return generatePath(SPACE_PATH, params); return generatePath(SPACE_PATH, params);
}; };
export const getSpaceLobbyPath = (spaceIdOrAlias: string): string => { export const getSpaceLobbyPath = (spaceIdOrAlias: string): string => {
const params = { const params = {
spaceIdOrAlias: encodeURIComponent(spaceIdOrAlias), spaceIdOrAlias,
}; };
return generatePath(SPACE_LOBBY_PATH, params); return generatePath(SPACE_LOBBY_PATH, params);
}; };
export const getSpaceSearchPath = (spaceIdOrAlias: string): string => { export const getSpaceSearchPath = (spaceIdOrAlias: string): string => {
const params = { const params = {
spaceIdOrAlias: encodeURIComponent(spaceIdOrAlias), spaceIdOrAlias,
}; };
return generatePath(SPACE_SEARCH_PATH, params); return generatePath(SPACE_SEARCH_PATH, params);
}; };
@@ -136,9 +136,9 @@ export const getSpaceRoomPath = (
eventId?: string, eventId?: string,
): string => { ): string => {
const params = { const params = {
spaceIdOrAlias: encodeURIComponent(spaceIdOrAlias), spaceIdOrAlias,
roomIdOrAlias: encodeURIComponent(roomIdOrAlias), roomIdOrAlias,
eventId: eventId ? encodeURIComponent(eventId) : null, eventId: eventId ?? null,
}; };
return generatePath(SPACE_ROOM_PATH, params); return generatePath(SPACE_ROOM_PATH, params);
@@ -148,7 +148,7 @@ export const getExplorePath = (): string => EXPLORE_PATH;
export const getExploreFeaturedPath = (): string => EXPLORE_FEATURED_PATH; export const getExploreFeaturedPath = (): string => EXPLORE_FEATURED_PATH;
export const getExploreServerPath = (server: string): string => { export const getExploreServerPath = (server: string): string => {
const params = { const params = {
server: encodeURIComponent(server), server,
}; };
return generatePath(EXPLORE_SERVER_PATH, params); return generatePath(EXPLORE_SERVER_PATH, params);
}; };