Closes #731 - Potential URL parse error

This commit is contained in:
Tom Moor
2018-08-02 00:18:19 -07:00
parent 4faccbcb4e
commit fc5a6127a5

View File

@@ -237,13 +237,19 @@ class DocumentScene extends React.Component<Props> {
onClickLink = (href: string) => {
if (isInternalUrl(href)) {
// relative
if (href[0] === '/') {
this.props.history.push(href);
let navigateTo = href;
// probably absolute
if (href[0] !== '/') {
try {
const url = new URL(href);
navigateTo = url.pathname;
} catch (err) {
navigateTo = href;
}
}
// absolute
const url = new URL(href);
this.props.history.push(url.pathname);
this.props.history.push(navigateTo);
} else {
window.open(href, '_blank');
}