Skip to content

Commit

Permalink
Added safeDecodeURI method. Closes umami-software#848.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Nov 22, 2021
1 parent b6ab8c3 commit 65d4094
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion components/metrics/PagesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import classNames from 'classnames';
import Link from 'next/link';
import FilterButtons from 'components/common/FilterButtons';
import { urlFilter } from 'lib/filters';
import { safeDecodeURI } from 'lib/url';
import usePageQuery from 'hooks/usePageQuery';
import MetricsTable from './MetricsTable';
import styles from './PagesTable.module.css';
Expand Down Expand Up @@ -35,7 +36,7 @@ export default function PagesTable({ websiteId, websiteDomain, showFilters, ...p
[styles.active]: x === url,
})}
>
{decodeURI(x)}
{safeDecodeURI(x)}
</a>
</Link>
);
Expand Down
5 changes: 3 additions & 2 deletions components/metrics/ReferrersTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FormattedMessage } from 'react-intl';
import MetricsTable from './MetricsTable';
import FilterButtons from 'components/common/FilterButtons';
import { refFilter } from 'lib/filters';
import { safeDecodeURI } from 'lib/url';

export const FILTER_DOMAIN_ONLY = 0;
export const FILTER_COMBINED = 1;
Expand All @@ -26,10 +27,10 @@ export default function ReferrersTable({ websiteId, websiteDomain, showFilters,
const renderLink = ({ w: href, x: url }) => {
return (href || url).startsWith('http') ? (
<a href={href || url} target="_blank" rel="noreferrer">
{decodeURI(url)}
{safeDecodeURI(url)}
</a>
) : (
decodeURI(url)
safeDecodeURI(url)
);
};

Expand Down
9 changes: 9 additions & 0 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,12 @@ export function getQueryString(params = {}) {
export function makeUrl(url, params) {
return `${url}${getQueryString(params)}`;
}

export function safeDecodeURI(s) {
try {
return decodeURI(s);
} catch (e) {
console.error(e);
}
return s;
}

0 comments on commit 65d4094

Please sign in to comment.