Added safeDecodeURI method. Closes #848.

This commit is contained in:
Mike Cao 2021-11-21 17:47:18 -08:00
parent b6ab8c381f
commit 65d4094095
3 changed files with 14 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import classNames from 'classnames';
import Link from 'next/link'; import Link from 'next/link';
import FilterButtons from 'components/common/FilterButtons'; import FilterButtons from 'components/common/FilterButtons';
import { urlFilter } from 'lib/filters'; import { urlFilter } from 'lib/filters';
import { safeDecodeURI } from 'lib/url';
import usePageQuery from 'hooks/usePageQuery'; import usePageQuery from 'hooks/usePageQuery';
import MetricsTable from './MetricsTable'; import MetricsTable from './MetricsTable';
import styles from './PagesTable.module.css'; import styles from './PagesTable.module.css';
@ -35,7 +36,7 @@ export default function PagesTable({ websiteId, websiteDomain, showFilters, ...p
[styles.active]: x === url, [styles.active]: x === url,
})} })}
> >
{decodeURI(x)} {safeDecodeURI(x)}
</a> </a>
</Link> </Link>
); );

View File

@ -3,6 +3,7 @@ import { FormattedMessage } from 'react-intl';
import MetricsTable from './MetricsTable'; import MetricsTable from './MetricsTable';
import FilterButtons from 'components/common/FilterButtons'; import FilterButtons from 'components/common/FilterButtons';
import { refFilter } from 'lib/filters'; import { refFilter } from 'lib/filters';
import { safeDecodeURI } from 'lib/url';
export const FILTER_DOMAIN_ONLY = 0; export const FILTER_DOMAIN_ONLY = 0;
export const FILTER_COMBINED = 1; export const FILTER_COMBINED = 1;
@ -26,10 +27,10 @@ export default function ReferrersTable({ websiteId, websiteDomain, showFilters,
const renderLink = ({ w: href, x: url }) => { const renderLink = ({ w: href, x: url }) => {
return (href || url).startsWith('http') ? ( return (href || url).startsWith('http') ? (
<a href={href || url} target="_blank" rel="noreferrer"> <a href={href || url} target="_blank" rel="noreferrer">
{decodeURI(url)} {safeDecodeURI(url)}
</a> </a>
) : ( ) : (
decodeURI(url) safeDecodeURI(url)
); );
}; };

View File

@ -32,3 +32,12 @@ export function getQueryString(params = {}) {
export function makeUrl(url, params) { export function makeUrl(url, params) {
return `${url}${getQueryString(params)}`; return `${url}${getQueryString(params)}`;
} }
export function safeDecodeURI(s) {
try {
return decodeURI(s);
} catch (e) {
console.error(e);
}
return s;
}