encodehtml
Version:
escaping and unescaping HTML entities – commonly needed utils to prevent XSS attacks when rendering user generated content
52 lines (38 loc) • 1.13 kB
JavaScript
var should = require('chai').should(),
encodehtml = require('../index'),
escape = encodehtml.escape,
unescape = encodehtml.unescape;
describe('#escape', function(){
it('converts & into &', function(){
escape('&').should.equal('&');
});
it('converts " into "', function() {
escape('"').should.equal('"');
});
it('converts \' into '', function() {
escape('\'').should.equal(''');
});
it('converts < into <', function() {
escape('<').should.equal('<');
});
it('converts > into >', function() {
escape('>').should.equal('>');
});
});
describe('#unescape', function(){
it('converts & into &', function() {
unescape('&').should.equal('&');
});
it('converts " into "', function() {
unescape('"').should.equal('"');
});
it('converts ' into \'', function() {
unescape(''').should.equal('\'');
});
it('converts < into <', function() {
unescape('<').should.equal('<');
});
it('converts > into >', function() {
unescape('>').should.equal('>');
});
});