Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

html-parser

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-parser - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

2

package.json
{
"name": "html-parser",
"version": "0.5.0",
"version": "0.6.0",
"description": "HTML/XML parser with less explosions",

@@ -5,0 +5,0 @@ "keywords": [ "html", "xml", "parser", "explosion" ],

@@ -67,3 +67,3 @@ var parseContext = require('./context');

if (name !== 'script' && name !== 'xmp') {
if (!/^(script|xmp)$/i.test(name)) {
return;

@@ -73,7 +73,7 @@ }

//just read until the closing tags for elements that allow cdata
var regex = new RegExp('^([\\s\\S]*?)(?:$|</' + name + '>)', 'i');
var regex = new RegExp('^([\\s\\S]*?)(?:$|</(' + name + ')\\s*>)', 'i');
var match = regex.exec(context.substring);
context.read(match[0].length);
context.callbacks.cdata(match[1]);
context.callbacks.closeElement(name);
context.callbacks.closeElement(match[2]);
}

@@ -80,0 +80,0 @@

@@ -155,2 +155,53 @@ var should = require('should');

});
it('closing script tags allow whitespace', function() {
var closeCount = 0, openCount = 0;
helpers.parseString('<script></script \n >', {
openElement: function(name) {
name.should.equal('script');
openCount++;
},
closeElement: function(name) {
name.should.equal('script');
closeCount++;
}
});
closeCount.should.equal(1);
openCount.should.equal(1);
});
it('closing xmp tags allow whitespace', function() {
var closeCount = 0, openCount = 0;
helpers.parseString('<xmp></xmp \n >', {
openElement: function(name) {
name.should.equal('xmp');
openCount++;
},
closeElement: function(name) {
name.should.equal('xmp');
closeCount++;
}
});
closeCount.should.equal(1);
openCount.should.equal(1);
});
it('closing script tag is not case sensitive', function() {
var closeCount = 0, openCount = 0;
helpers.parseString('<script></SCRIPT>', {
openElement: function(name) {
name.should.equal('script');
openCount++;
},
closeElement: function(name) {
name.should.equal('SCRIPT');
closeCount++;
}
});
closeCount.should.equal(1);
openCount.should.equal(1);
});
});

@@ -88,2 +88,26 @@ var should = require('should');

});
it('should remove element with attributes', function() {
var html = '<foo><bar baz="bat"></bar></foo>';
var sanitized = helpers.parser.sanitize(html, {
elements: [ 'bar' ]
});
sanitized.should.equal('<foo></foo>');
});
it('should remove script tag with whitespace', function() {
var html = '<p>foo<script ></script ></p>';
var sanitized = helpers.parser.sanitize(html, {
elements: [ 'script' ]
});
sanitized.should.equal('<p>foo</p>');
});
it('should remove script tag with attributes', function() {
var html = '<p>foo<script type="text/javascript">alert("foo");</script></p>';
var sanitized = helpers.parser.sanitize(html, {
elements: [ 'script' ]
});
sanitized.should.equal('<p>foo</p>');
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc