viewbadges: function(target, room, user) { if (!this.can('mute', null, room)) return false; if (!this.canBroadcast()) return; if (room.id !== 'thejohtoleague') return this.sendReply('You can only use badges in the Official league room.'); var sanitize = require('sanitize'); if (!target) { userid = user.userid; username = sanitize(user.name); } else { userid = toId(target); username = sanitize(target); } self = this; fs.readFile('config/badges.txt','utf8',function(err, data) { if (err) { self.sendReplyBox(username+' has no badges.'); room.update(); return true; } line = data.split('\n'); badges = ''; for (var u in line) { row = line[u].split(','); if (row[0] != userid) continue; for (var x in row) { if (row[x] != userid) { badges = badges + row[x] + ','; } } } glbadge = ''; e4badge = ''; if (badges.indexOf('dark') >= 0) glbadge = glbadge + '<img title="Dark" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/044_zps7894afc4.png"/>'; if (badges.indexOf('dragon') >= 0) glbadge = glbadge + '<img title="Dragon" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/142_zpsea0762e7.png"/>'; if (badges.indexOf('electric') >= 0) glbadge = glbadge + '<img title="Electric" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/019_zps1c48a4cf.png"/>'; if (badges.indexOf('normal') >= 0) glbadge = glbadge + '<img title="Normal" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/091_zpsf2934626.png"/>'; if (badges.indexOf('rock') >= 0) glbadge = glbadge + '<img title="Rock" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/097_zpsad64274a.png"/>'; if (badges.indexOf('fire') >= 0) glbadge = glbadge + '<img title="Fire" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/062_zpsa4a9ad16.png"/>'; if (badges.indexOf('steel') >= 0) glbadge = glbadge + '<img title="Steel" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/131_zpsc82e5e53.png"/>'; if (badges.indexOf('grass') >= 0) glbadge = glbadge + '<img title="Grass" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/002_zpsf02c0411.png"/>'; if (badges.indexOf('bug') >= 0) glbadge = glbadge + '<img title="Bug" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/061_zps01c1d2a3.png"/>'; if (badges.indexOf('psychic') >= 0) glbadge = glbadge + '<img title="Psychic" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/091_zpsc55ac97a.png"/>'; if (badges.indexOf('fairy') >= 0) glbadge = glbadge + '<img title="Fairy" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/033_zps778a8f48.png"/>'; if (badges.indexOf('water') >= 0) glbadge = glbadge + '<img title="Water" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/094_zps41b18534.png"/>'; if (badges.indexOf('ghost') >= 0) glbadge = glbadge + '<img title="Ghost" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/094_zps992c377f.png"/>'; if (badges.indexOf('flying') >= 0) glbadge = glbadge + '<img title="Flying" src="http://i.picresize.com/images/2014/03/16/7gG9.png"/>'; if (badges.indexOf('ground') >= 0) glbadge = glbadge + '<img title="Ground" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/003_zps7b109aa5.png"/>'; if (badges.indexOf('fighting') >= 0) glbadge = glbadge + '<img title="Fighting" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/146_zps098d23fa.png"/>'; if (badges.indexOf('poison') >= 0) glbadge = glbadge + '<img title="Poison" src="http://i1305.photobucket.com/albums/s542/TheBattleTowerPS/018_zps7add8bf3.png"/>'; if (badges.indexOf('flying') >= 0) e4badge = e4badge + '<img title="Elite Four Almighty Bronzong (Flying)" src="http://i.picresize.com/images/2014/05/18/ZArtW.png"/>'; if (badges.indexOf('flame') >= 0) e4badge = e4badge + '<img title="Elite Four Hydrostatics (Fire)" src="http://i.picresize.com/images/2014/05/18/81wmV.png"/>'; if (badges.indexOf('steel') >= 0) e4badge = e4badge + '<img title="Elite Four X ADN Y DUDEET (Steel)" src="http://i.picresize.com/images/2014/05/18/s7aTl.png"/>'; if (badges.indexOf('poison') >= 0) e4badge = e4badge + '<img title="Elite Four Kecleon Market (Poison)" src="http://i.picresize.com/images/2014/05/18/MULKs.png"/>'; if (glbadge == '' && e4badge == '') return self.sendReplyBox(username+' has no badges.'); self.sendReplyBox('<center>'+username+'\'s badges <br /><br />Gym Leader Badges:<br />'+glbadge+'<br />Elite Four Badges: <br />'+e4badge+'</center>'); room.update(); }); },
it('can handle nested error html', function() { var code = [ '<div>foo <p class="foo">foo <p class="bar">bar</p></p>', '<a href="#">anchor</a>', '<pre><code><script> script</code></script></pre>', '<div><span><p></p><i>italic</i>' ].join('') var ret = sanitize(code) notContain(ret, 'class'); })
xhr('./cases/' + name + '.html', function(text) { var ret = sanitize(text) notContain(ret, 'color'); done() })
it('should unwrap article', function() { var ret = sanitize('<article><dt>bar</dt></article>') assert(ret, 'bar') });
it('should remove blank tags', function() { var ret = sanitize('<i>foo <b>bold</b><p></p></i>') assert(ret, '<em>foo <strong>bold</strong></em>') })
it('should remove comments', function() { var ret = sanitize('<!-- comment -->foo') assert(ret, 'foo') })
it('can replace complex html', function() { var ret = sanitize('<i>foo <b>bold</b></i>') assert(ret, '<em>foo <strong>bold</strong></em>') })
it('should keep href only', function() { var ret = sanitize('<a href="#" name="baz" class="baz" style="foo">foo</a> bar') assert(ret, '<a href="#">foo</a> bar') })
it('should replace i with em', function() { var ret = sanitize('<i>foo</i> bar') assert(ret, '<em>foo</em> bar') })
it('should unwrap span', function() { var ret = sanitize('<span>foo</span> bar') assert(ret, 'foo bar') })
it('should has no script', function() { var ret = sanitize('<script>foo</script>bar') assert(ret, 'bar') })