From fc5a6127a5aa8917f491c1cb4b1134e476e8878c Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 2 Aug 2018 00:18:19 -0700 Subject: [PATCH] Closes #731 - Potential URL parse error --- app/scenes/Document/Document.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/scenes/Document/Document.js b/app/scenes/Document/Document.js index f5f194f12..763a54092 100644 --- a/app/scenes/Document/Document.js +++ b/app/scenes/Document/Document.js @@ -237,13 +237,19 @@ class DocumentScene extends React.Component { 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'); }