Skip to content

Commit

Permalink
Add HTML entity decoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
evl committed Jan 20, 2012
1 parent b6fd319 commit 7b3fe16
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/plugins/spotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports.configure = function(client) {
var matches;

if ((matches = titlePattern.exec(body))) {
meta.title = matches[1];
meta.title = matches[1].decodeEntities();

client.say(to, 'Spotify'.bold + ': ' + meta.title);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/wimp.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports.configure = function(client) {
var titleMatches = body.match(/<title>(.+)\s\-\s/);

if (titleMatches) {
meta.title = titleMatches[0];
meta.title = titleMatches[0].decodeEntities();

client.say(to, 'WiMP'.bold + ': ' + meta.title);
}
Expand Down
16 changes: 16 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ String.prototype.repeat = function(count) {
return new Array(count + 1).join(this);
};

var entities = {
'amp': '&',
'lt': '<',
'gt': '>',
'quot':
'"'
};

String.prototype.decodeEntities = function() {
return this.replace(/&#(\d+);/g, function(value, charCode) {
return String.fromCharCode(parseInt(charCode, 10));
}).replace(/&([a-z]+);/g, function(value, entity) {
return entities[entity] || '';
});
};

String.prototype.__defineGetter__('bold', function() {
return String.fromCharCode(2) + this + String.fromCharCode(15);
});
Expand Down

0 comments on commit 7b3fe16

Please sign in to comment.