actually, only intercept URLs which are explicitly referring to our current app
This commit is contained in:
parent
1aed9ccbf4
commit
d54a75c913
2 changed files with 10 additions and 8 deletions
|
@ -47,10 +47,9 @@ var sanitizeHtmlParams = {
|
||||||
transformTags: { // custom to matrix
|
transformTags: { // custom to matrix
|
||||||
// add blank targets to all hyperlinks except vector URLs
|
// add blank targets to all hyperlinks except vector URLs
|
||||||
'a': function(tagName, attribs) {
|
'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);
|
var m = attribs.href.match(linkifyMatrix.VECTOR_URL_PATTERN);
|
||||||
if (m) {
|
if (m) {
|
||||||
return { tagName: 'a', attribs: { href: m[4] } };
|
return { tagName: 'a', attribs: { href: attribs.href } };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return { tagName: 'a', attribs: { href: attribs.href, target: '_blank'} };
|
return { tagName: 'a', attribs: { href: attribs.href, target: '_blank'} };
|
||||||
|
|
|
@ -98,7 +98,15 @@ function matrixLinkify(linkify) {
|
||||||
matrixLinkify.onUserClick = function(e, userId) { e.preventDefault(); };
|
matrixLinkify.onUserClick = function(e, userId) { e.preventDefault(); };
|
||||||
matrixLinkify.onAliasClick = function(e, roomAlias) { 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 = {
|
matrixLinkify.options = {
|
||||||
events: function (href, type) {
|
events: function (href, type) {
|
||||||
|
@ -124,11 +132,6 @@ matrixLinkify.options = {
|
||||||
return '#/room/' + href;
|
return '#/room/' + href;
|
||||||
case 'userid':
|
case 'userid':
|
||||||
return '#';
|
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:
|
default:
|
||||||
return href;
|
return href;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue