parseMatrixToUser,
testMatrixTo,
} from '../../plugins/matrix-to';
+import { tryDecodeURIComponent } from '../../utils/dom';
const markNodeToType: Record<string, MarkType> = {
b: MarkType.Bold,
return createEmoticonElement(src, alt || 'Unknown Emoji');
}
if (node.name === 'a') {
- const href = decodeURIComponent(node.attribs.href);
+ const href = tryDecodeURIComponent(node.attribs.href);
if (typeof href !== 'string') return undefined;
if (testMatrixTo(href)) {
const userMention = parseMatrixToUser(href);
useIntersectionObserver,
} from '../../hooks/useIntersectionObserver';
import * as css from './UrlPreviewCard.css';
+import { tryDecodeURIComponent } from '../../utils/dom';
const linkStyles = { color: color.Success.Main };
priority="300"
>
{typeof prev['og:site_name'] === 'string' && `${prev['og:site_name']} | `}
- {decodeURIComponent(url)}
+ {tryDecodeURIComponent(url)}
</Text>
<Text truncate priority="400">
<b>{prev['og:title']}</b>
import { AuthFlowsLoader } from '../../components/AuthFlowsLoader';
import { AuthFlowsProvider } from '../../hooks/useAuthFlows';
import { AuthServerProvider } from '../../hooks/useAuthServer';
+import { tryDecodeURIComponent } from '../../utils/dom';
const currentAuthPath = (pathname: string): string => {
if (matchPath(LOGIN_PATH, pathname)) {
const clientConfig = useClientConfig();
const defaultServer = clientDefaultServer(clientConfig);
- let server: string = urlEncodedServer ? decodeURIComponent(urlEncodedServer) : defaultServer;
+ let server: string = urlEncodedServer ? tryDecodeURIComponent(urlEncodedServer) : defaultServer;
if (!clientAllowedServer(clientConfig, server)) {
server = defaultServer;
// if server is mismatches with path server, update path
useEffect(() => {
- if (!urlEncodedServer || decodeURIComponent(urlEncodedServer) !== server) {
+ if (!urlEncodedServer || tryDecodeURIComponent(urlEncodedServer) !== server) {
navigate(
generatePath(currentAuthPath(location.pathname), {
server: encodeURIComponent(server),
testMatrixTo,
} from './matrix-to';
import { onEnterOrSpace } from '../utils/keyboard';
+import { tryDecodeURIComponent } from '../utils/dom';
const ReactPrism = lazy(() => import('./react-prism/ReactPrism'));
attributes,
content,
}) => {
- if (tagName === 'a' && testMatrixTo(decodeURIComponent(attributes.href))) {
- const mention = mentionRender(decodeURIComponent(attributes.href));
+ if (tagName === 'a' && testMatrixTo(tryDecodeURIComponent(attributes.href))) {
+ const mention = mentionRender(tryDecodeURIComponent(attributes.href));
if (mention) return mention;
}
}
}
- if (name === 'a' && testMatrixTo(decodeURIComponent(props.href))) {
+ if (name === 'a' && testMatrixTo(tryDecodeURIComponent(props.href))) {
const mention = renderMatrixMention(
mx,
roomId,
- decodeURIComponent(props.href),
+ tryDecodeURIComponent(props.href),
makeMentionCustomProps(params.handleMentionClick)
);
if (mention) return mention;
if (!favicon) return;
favicon.setAttribute('href', url);
};
+
+export const tryDecodeURIComponent = (encodedURIComponent: string): string => {
+ try {
+ return decodeURIComponent(encodedURIComponent);
+ } catch {
+ return encodedURIComponent;
+ }
+};