Fix for room links in /whois and /rooms

This commit is contained in:
Cathy J. Fitzpatrick
2013-02-12 15:18:43 -07:00
parent 20e0a9b677
commit db80ef64c7

View File

@@ -312,11 +312,27 @@ var Tools = {
// In addition to the normal whitelist, allow target='_blank'.
// html.sanitizeAttribs is not very customisable, so this a bit ugly.
var blankIdx = undefined;
var extra = [];
if (tagName === 'a') {
for (var i = 0; i < attribs.length - 1; ++i) {
if ((attribs[i] === 'target') && (attribs[i + 1] === '_blank')) {
blankIdx = i + 1;
break;
for (var i = 0; i < attribs.length - 1; i += 2) {
switch (attribs[i]) {
case 'target':
if (attribs[i + 1] === '_blank') {
blankIdx = i + 1;
}
break;
case 'room':
// Special custom attribute for linking to a room.
// This attribute will be stripped by `sanitizeAttribs`
// below, and is only used to signal to add an `onclick`
// handler here.
if (!(/^[a-z0-9\-]*$/.test(attribs[i + 1]))) {
// Bogus roomid - could be used to inject JavaScript.
break;
}
extra.push('onclick');
extra.push('return selectTab(\'' + attribs[i + 1] + '\');');
break;
}
}
}
@@ -324,6 +340,9 @@ var Tools = {
if (blankIdx !== undefined) {
attribs[blankIdx] = '_blank';
}
if (extra.length > 0) {
attribs = attribs.concat(extra);
}
return {attribs: attribs};
};
return function(input) {