Properly escape HTML entities in irclinky filter

Fixes #525
This commit is contained in:
Lorenz Hübschle-Schneider 2014-12-30 18:22:20 +01:00
parent 82fc20ed0d
commit 1478b611da

View file

@ -30,6 +30,13 @@ weechat.filter('irclinky', ['$filter', function($filter) {
return text;
}
// First, escape entities to prevent escaping issues because it's a bad idea
// to parse/modify HTML with regexes, which we do a couple of lines down...
var entities = {"<": "&lt;", ">": "&gt;", '"': '&quot;', "'": '&#39;', "&": "&amp;", "/": '&#x2F;'};
text = text.replace(/[<>"'&\/]/g, function (char) {
return entities[char];
});
// This regex in no way matches all IRC channel names (they could also begin with &, + or an
// exclamation mark followed by 5 alphanumeric characters, and are bounded in length by 50).
// However, it matches all *common* IRC channels while trying to minimise false positives.