revert(router): drop tryDecodeURIComponent helper usage
This reverts commit bfd792e8fa.
This commit is contained in:
14 files changed
+42
-60
No files matched your search
@@ -8,7 +8,6 @@ import {
|
||||
getSpacePath,
|
||||
} from '../pages/pathUtils';
|
||||
import { DIRECT_PATH, EXPLORE_PATH, HOME_PATH, INBOX_PATH, SPACE_PATH } from '../pages/paths';
|
||||
import { tryDecodeURIComponent } from '../utils/dom';
|
||||
|
||||
type BackRouteHandlerProps = {
|
||||
children: (onBack: () => void) => ReactNode;
|
||||
|
||||
@@ -25,7 +25,6 @@ import {
|
||||
parseMatrixToUser,
|
||||
testMatrixTo,
|
||||
} from '$plugins/matrix-to';
|
||||
import { tryDecodeURIComponent } from '$appUtils/dom';
|
||||
import { escapeMarkdownInlineSequences, escapeMarkdownBlockSequences } from '$plugins/markdown';
|
||||
|
||||
type ProcessTextCallback = (text: string) => string;
|
||||
@@ -98,8 +97,9 @@ const getInlineNonMarkElement = (node: Element): MentionElement | EmoticonElemen
|
||||
return createEmoticonElement(src, alt || 'Unknown Emoji');
|
||||
}
|
||||
if (node.name === 'a') {
|
||||
const href = tryDecodeURIComponent(node.attribs.href);
|
||||
if (typeof href !== 'string') return undefined;
|
||||
const encodedHref = node.attribs.href;
|
||||
const href = encodedHref && decodeURIComponent(encodedHref);
|
||||
if (!href) return undefined;
|
||||
if (testMatrixTo(href)) {
|
||||
const userMention = parseMatrixToUser(href);
|
||||
if (userMention) {
|
||||
|
||||
@@ -19,7 +19,6 @@ import {
|
||||
import { stopPropagation } from '$appUtils/keyboard';
|
||||
import { isRoomAlias, isRoomId } from '$appUtils/matrix';
|
||||
import { parseMatrixToRoom, parseMatrixToRoomEvent, testMatrixTo } from '$plugins/matrix-to';
|
||||
import { tryDecodeURIComponent } from '$appUtils/dom';
|
||||
|
||||
type JoinAddressProps = {
|
||||
onOpen: (roomIdOrAlias: string, via?: string[], eventId?: string) => void;
|
||||
@@ -43,7 +42,8 @@ export function JoinAddressPrompt({ onOpen, onCancel }: JoinAddressProps) {
|
||||
}
|
||||
|
||||
if (testMatrixTo(address)) {
|
||||
const decodedAddress = tryDecodeURIComponent(address);
|
||||
const encodedAddress = address;
|
||||
const decodedAddress = encodedAddress && decodeURIComponent(encodedAddress);
|
||||
const toRoom = parseMatrixToRoom(decodedAddress);
|
||||
if (toRoom) {
|
||||
onOpen(toRoom.roomIdOrAlias, toRoom.viaServers);
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
useIntersectionObserver,
|
||||
} from '$hooks/useIntersectionObserver';
|
||||
import * as css from './UrlPreviewCard.css';
|
||||
import { tryDecodeURIComponent } from '$appUtils/dom';
|
||||
import { mxcUrlToHttp } from '$appUtils/matrix';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
|
||||
@@ -29,6 +28,9 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number }>(
|
||||
|
||||
if (previewStatus.status === AsyncStatus.Error) return null;
|
||||
|
||||
const encodedUrl = url;
|
||||
const decodedUrl = encodedUrl && decodeURIComponent(encodedUrl);
|
||||
|
||||
const renderContent = (prev: IPreviewUrlResponse) => {
|
||||
const imgUrl = mxcUrlToHttp(
|
||||
mx,
|
||||
@@ -55,7 +57,7 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number }>(
|
||||
priority="300"
|
||||
>
|
||||
{typeof prev['og:site_name'] === 'string' && `${prev['og:site_name']} | `}
|
||||
{tryDecodeURIComponent(url)}
|
||||
{decodedUrl || url}
|
||||
</Text>
|
||||
<Text truncate priority="400">
|
||||
<b>{prev['og:title']}</b>
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { getCanonicalAliasRoomId, isRoomAlias } from '$appUtils/matrix';
|
||||
import { tryDecodeURIComponent } from '$appUtils/dom';
|
||||
import { useMatrixClient } from '../useMatrixClient';
|
||||
|
||||
export const useSelectedRoom = (): string | undefined => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
const { roomIdOrAlias: encodedRoomIdOrAlias } = useParams();
|
||||
const roomIdOrAlias = encodedRoomIdOrAlias
|
||||
? tryDecodeURIComponent(encodedRoomIdOrAlias)
|
||||
: undefined;
|
||||
const roomIdOrAlias = encodedRoomIdOrAlias && decodeURIComponent(encodedRoomIdOrAlias);
|
||||
const roomId =
|
||||
roomIdOrAlias && isRoomAlias(roomIdOrAlias)
|
||||
? getCanonicalAliasRoomId(mx, roomIdOrAlias)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { useMatch, useParams } from 'react-router-dom';
|
||||
import { getCanonicalAliasRoomId, isRoomAlias } from '$appUtils/matrix';
|
||||
import { tryDecodeURIComponent } from '$appUtils/dom';
|
||||
import { useMatrixClient } from '../useMatrixClient';
|
||||
import { getSpaceLobbyPath, getSpaceSearchPath } from '$pages/pathUtils';
|
||||
|
||||
@@ -8,9 +7,7 @@ export const useSelectedSpace = (): string | undefined => {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
const { spaceIdOrAlias: encodedSpaceIdOrAlias } = useParams();
|
||||
const spaceIdOrAlias = encodedSpaceIdOrAlias
|
||||
? tryDecodeURIComponent(encodedSpaceIdOrAlias)
|
||||
: undefined;
|
||||
const spaceIdOrAlias = encodedSpaceIdOrAlias && decodeURIComponent(encodedSpaceIdOrAlias);
|
||||
|
||||
const spaceId =
|
||||
spaceIdOrAlias && isRoomAlias(spaceIdOrAlias)
|
||||
|
||||
@@ -68,7 +68,6 @@ import { Create } from './client/create';
|
||||
import { CreateSpaceModalRenderer } from '../features/create-space';
|
||||
import { SearchModalRenderer } from '../features/search';
|
||||
import { getFallbackSession } from '../state/sessions';
|
||||
import { tryDecodeURIComponent } from '../utils/dom';
|
||||
import { pushSessionToSW } from '../../sw-session';
|
||||
|
||||
export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize) => {
|
||||
@@ -224,9 +223,12 @@ export const createRouter = (clientConfig: ClientConfig, screenSize: ScreenSize)
|
||||
<Route
|
||||
index
|
||||
loader={({ params }) => {
|
||||
const { spaceIdOrAlias } = params;
|
||||
if (spaceIdOrAlias) {
|
||||
return redirect(getSpaceLobbyPath(tryDecodeURIComponent(spaceIdOrAlias)));
|
||||
const encodedSpaceIdOrAlias = params.spaceIdOrAlias;
|
||||
const decodedSpaceIdOrAlias =
|
||||
encodedSpaceIdOrAlias && decodeURIComponent(encodedSpaceIdOrAlias);
|
||||
|
||||
if (decodedSpaceIdOrAlias) {
|
||||
return redirect(getSpaceLobbyPath(decodedSpaceIdOrAlias));
|
||||
}
|
||||
return null;
|
||||
}}
|
||||
|
||||
@@ -25,7 +25,6 @@ import { AutoDiscoveryInfoProvider } from '$hooks/useAutoDiscoveryInfo';
|
||||
import { AuthFlowsLoader } from '$components/AuthFlowsLoader';
|
||||
import { AuthFlowsProvider } from '$hooks/useAuthFlows';
|
||||
import { AuthServerProvider } from '$hooks/useAuthServer';
|
||||
import { tryDecodeURIComponent } from '$appUtils/dom';
|
||||
|
||||
const currentAuthPath = (pathname: string): string => {
|
||||
if (matchPath(LOGIN_PATH, pathname)) {
|
||||
@@ -69,7 +68,8 @@ export function AuthLayout() {
|
||||
const clientConfig = useClientConfig();
|
||||
|
||||
const defaultServer = clientDefaultServer(clientConfig);
|
||||
let server: string = urlEncodedServer ? tryDecodeURIComponent(urlEncodedServer) : defaultServer;
|
||||
const decodedServer = urlEncodedServer && decodeURIComponent(urlEncodedServer);
|
||||
let server: string = decodedServer ?? defaultServer;
|
||||
|
||||
if (!clientAllowedServer(clientConfig, server)) {
|
||||
server = defaultServer;
|
||||
@@ -91,7 +91,7 @@ export function AuthLayout() {
|
||||
|
||||
// if server is mismatches with path server, update path
|
||||
useEffect(() => {
|
||||
if (!urlEncodedServer || tryDecodeURIComponent(urlEncodedServer) !== server) {
|
||||
if (!urlEncodedServer || decodedServer !== server) {
|
||||
navigate(
|
||||
generatePath(currentAuthPath(location.pathname), {
|
||||
server: encodeURIComponent(server),
|
||||
@@ -99,7 +99,7 @@ export function AuthLayout() {
|
||||
{ replace: true }
|
||||
);
|
||||
}
|
||||
}, [urlEncodedServer, navigate, location, server]);
|
||||
}, [decodedServer, urlEncodedServer, navigate, location, server]);
|
||||
|
||||
const selectServer = useCallback(
|
||||
(newServer: string) => {
|
||||
|
||||
@@ -5,17 +5,14 @@ import { IsDirectRoomProvider, RoomProvider } from '$hooks/useRoom';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { JoinBeforeNavigate } from '$features/join-before-navigate';
|
||||
import { useDirectRooms } from './useDirectRooms';
|
||||
import { tryDecodeURIComponent } from '$appUtils/dom';
|
||||
|
||||
export function DirectRouteRoomProvider({ children }: { children: ReactNode }) {
|
||||
const mx = useMatrixClient();
|
||||
const rooms = useDirectRooms();
|
||||
|
||||
const { roomIdOrAlias: encodedRoomIdOrAlias, eventId: encodedEventId } = useParams();
|
||||
const roomIdOrAlias = encodedRoomIdOrAlias
|
||||
? tryDecodeURIComponent(encodedRoomIdOrAlias)
|
||||
: undefined;
|
||||
const eventId = encodedEventId ? tryDecodeURIComponent(encodedEventId) : undefined;
|
||||
const roomIdOrAlias = encodedRoomIdOrAlias && decodeURIComponent(encodedRoomIdOrAlias);
|
||||
const eventId = encodedEventId && decodeURIComponent(encodedEventId);
|
||||
const roomId = useSelectedRoom();
|
||||
const room = mx.getRoom(roomId);
|
||||
|
||||
|
||||
@@ -6,17 +6,14 @@ import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { JoinBeforeNavigate } from '$features/join-before-navigate';
|
||||
import { useHomeRooms } from './useHomeRooms';
|
||||
import { useSearchParamsViaServers } from '$hooks/router/useSearchParamsViaServers';
|
||||
import { tryDecodeURIComponent } from '$appUtils/dom';
|
||||
|
||||
export function HomeRouteRoomProvider({ children }: { children: ReactNode }) {
|
||||
const mx = useMatrixClient();
|
||||
const rooms = useHomeRooms();
|
||||
|
||||
const { roomIdOrAlias: encodedRoomIdOrAlias, eventId: encodedEventId } = useParams();
|
||||
const roomIdOrAlias = encodedRoomIdOrAlias
|
||||
? tryDecodeURIComponent(encodedRoomIdOrAlias)
|
||||
: undefined;
|
||||
const eventId = encodedEventId ? tryDecodeURIComponent(encodedEventId) : undefined;
|
||||
const roomIdOrAlias = encodedRoomIdOrAlias && decodeURIComponent(encodedRoomIdOrAlias);
|
||||
const eventId = encodedEventId && decodeURIComponent(encodedEventId);
|
||||
const viaServers = useSearchParamsViaServers();
|
||||
const roomId = useSelectedRoom();
|
||||
const room = mx.getRoom(roomId);
|
||||
|
||||
@@ -7,7 +7,6 @@ import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { JoinBeforeNavigate } from '$features/join-before-navigate';
|
||||
import { useSpace } from '$hooks/useSpace';
|
||||
import { getAllParents, getSpaceChildren } from '$appUtils/room';
|
||||
import { tryDecodeURIComponent } from '$appUtils/dom';
|
||||
import { roomToParentsAtom } from '$state/room/roomToParents';
|
||||
import { allRoomsAtom } from '$state/room-list/roomList';
|
||||
import { useSearchParamsViaServers } from '$hooks/router/useSearchParamsViaServers';
|
||||
@@ -24,10 +23,8 @@ export function SpaceRouteRoomProvider({ children }: { children: ReactNode }) {
|
||||
const allRooms = useAtomValue(allRoomsAtom);
|
||||
|
||||
const { roomIdOrAlias: encodedRoomIdOrAlias, eventId: encodedEventId } = useParams();
|
||||
const roomIdOrAlias = encodedRoomIdOrAlias
|
||||
? tryDecodeURIComponent(encodedRoomIdOrAlias)
|
||||
: undefined;
|
||||
const eventId = encodedEventId ? tryDecodeURIComponent(encodedEventId) : undefined;
|
||||
const roomIdOrAlias = encodedRoomIdOrAlias && decodeURIComponent(encodedRoomIdOrAlias);
|
||||
const eventId = encodedEventId && decodeURIComponent(encodedEventId);
|
||||
const viaServers = useSearchParamsViaServers();
|
||||
const roomId = useSelectedRoom();
|
||||
const room = mx.getRoom(roomId);
|
||||
|
||||
@@ -7,7 +7,6 @@ import { useSelectedSpace } from '$hooks/router/useSelectedSpace';
|
||||
import { SpaceProvider } from '$hooks/useSpace';
|
||||
import { JoinBeforeNavigate } from '$features/join-before-navigate';
|
||||
import { useSearchParamsViaServers } from '$hooks/router/useSearchParamsViaServers';
|
||||
import { tryDecodeURIComponent } from '$appUtils/dom';
|
||||
|
||||
type RouteSpaceProviderProps = {
|
||||
children: ReactNode;
|
||||
@@ -17,9 +16,7 @@ export function RouteSpaceProvider({ children }: RouteSpaceProviderProps) {
|
||||
const joinedSpaces = useSpaces(mx, allRoomsAtom);
|
||||
|
||||
const { spaceIdOrAlias: encodedSpaceIdOrAlias } = useParams();
|
||||
const spaceIdOrAlias = encodedSpaceIdOrAlias
|
||||
? tryDecodeURIComponent(encodedSpaceIdOrAlias)
|
||||
: undefined;
|
||||
const spaceIdOrAlias = encodedSpaceIdOrAlias && decodeURIComponent(encodedSpaceIdOrAlias);
|
||||
const viaServers = useSearchParamsViaServers();
|
||||
|
||||
const selectedSpaceId = useSelectedSpace();
|
||||
|
||||
@@ -40,7 +40,7 @@ import {
|
||||
testMatrixTo,
|
||||
} from './matrix-to';
|
||||
import { onEnterOrSpace } from '../utils/keyboard';
|
||||
import { copyToClipboard, tryDecodeURIComponent } from '../utils/dom';
|
||||
import { copyToClipboard } from '../utils/dom';
|
||||
import { useTimeoutToggle } from '../hooks/useTimeoutToggle';
|
||||
|
||||
const ReactPrism = lazy(() => import('./react-prism/ReactPrism'));
|
||||
@@ -156,8 +156,11 @@ export const factoryRenderLinkifyWithMention = (
|
||||
attributes,
|
||||
content,
|
||||
}) => {
|
||||
if (tagName === 'a' && testMatrixTo(tryDecodeURIComponent(attributes.href))) {
|
||||
const mention = mentionRender(tryDecodeURIComponent(attributes.href));
|
||||
const encodedHref = attributes.href;
|
||||
const decodedHref = encodedHref && decodeURIComponent(encodedHref);
|
||||
|
||||
if (tagName === 'a' && decodedHref && testMatrixTo(decodedHref)) {
|
||||
const mention = mentionRender(decodedHref);
|
||||
if (mention) return mention;
|
||||
}
|
||||
|
||||
@@ -442,11 +445,13 @@ export const getReactCustomHtmlParser = (
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
name === 'a' &&
|
||||
typeof props.href === 'string' &&
|
||||
testMatrixTo(tryDecodeURIComponent(props.href))
|
||||
) {
|
||||
if (name === 'a' && typeof props.href === 'string') {
|
||||
const encodedHref = props.href;
|
||||
const decodedHref = encodedHref && decodeURIComponent(encodedHref);
|
||||
if (!decodedHref || !testMatrixTo(decodedHref)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const content = children.find((child) => !(child instanceof DOMText))
|
||||
? undefined
|
||||
: children.map((c) => (c instanceof DOMText ? c.data : '')).join();
|
||||
@@ -454,7 +459,7 @@ export const getReactCustomHtmlParser = (
|
||||
const mention = renderMatrixMention(
|
||||
mx,
|
||||
roomId,
|
||||
tryDecodeURIComponent(props.href),
|
||||
decodedHref,
|
||||
makeMentionCustomProps(params.handleMentionClick, content)
|
||||
);
|
||||
|
||||
|
||||
@@ -211,14 +211,6 @@ export const setFavicon = (url: string): void => {
|
||||
favicon.setAttribute('href', url);
|
||||
};
|
||||
|
||||
export const tryDecodeURIComponent = (encodedURIComponent: string): string => {
|
||||
try {
|
||||
return decodeURIComponent(encodedURIComponent);
|
||||
} catch {
|
||||
return encodedURIComponent;
|
||||
}
|
||||
};
|
||||
|
||||
export const syntaxErrorPosition = (error: SyntaxError): number | undefined => {
|
||||
const match = error.message.match(/position\s(\d+)\s/);
|
||||
if (!match) return undefined;
|
||||
|
||||
Reference in new issue
Block a user