diff --git a/src/HtmlUtils.js b/src/HtmlUtils.js index 1412112260..18de137634 100644 --- a/src/HtmlUtils.js +++ b/src/HtmlUtils.js @@ -47,10 +47,9 @@ var sanitizeHtmlParams = { transformTags: { // custom to matrix // add blank targets to all hyperlinks except vector URLs 'a': function(tagName, attribs) { - // XXX: use matrix.to instead and deduplicate regexp with linkify-matrix.js var m = attribs.href.match(linkifyMatrix.VECTOR_URL_PATTERN); if (m) { - return { tagName: 'a', attribs: { href: m[4] } }; + return { tagName: 'a', attribs: { href: attribs.href } }; } else { return { tagName: 'a', attribs: { href: attribs.href, target: '_blank'} }; diff --git a/src/linkify-matrix.js b/src/linkify-matrix.js index 51e4af044f..bb9b7d5c81 100644 --- a/src/linkify-matrix.js +++ b/src/linkify-matrix.js @@ -98,7 +98,15 @@ function matrixLinkify(linkify) { matrixLinkify.onUserClick = function(e, userId) { e.preventDefault(); }; matrixLinkify.onAliasClick = function(e, roomAlias) { e.preventDefault(); }; -matrixLinkify.VECTOR_URL_PATTERN = /(https?:\/\/)?(www\.)?vector\.im\/(beta|staging|develop)?\/(#.*)/; +var escapeRegExp = function(string) { + return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); +}; + +// we only recognise URLs which match our current URL as being the same app +// as if someone explicitly links to vector.im/develop and we're on vector.im/beta +// they may well be trying to get us to explicitly go to develop. +// FIXME: intercept matrix.to URLs as well. +matrixLinkify.VECTOR_URL_PATTERN = "(https?:\/\/)?" + escapeRegExp(window.location.host + window.location.pathname); matrixLinkify.options = { events: function (href, type) { @@ -124,11 +132,6 @@ matrixLinkify.options = { return '#/room/' + href; case 'userid': return '#'; - case 'url': - // intercept vector links directly into the app - // FIXME: use matrix.to asap, as this is fragile as sin - var m = href.match(matrixLinkify.VECTOR_URL_PATTERN); - return m ? m[4] : href; default: return href; }