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.1.0 to 0.2.0

README.md

30

package.json
{
"name": "html-parser",
"version": "0.1.0",
"description": "HTML/XML parser with less explosions",
"author": {
"name": "Tommy Montgomery",
"email": "tmont@tmont.com",
"url": "http://tmont.com/"
},
"name": "html-parser",
"version": "0.2.0",
"description": "HTML/XML parser with less explosions",
"keywords": [ "html", "xml", "parser", "explosion" ],
"author": {
"name": "Tommy Montgomery",
"email": "tmont@tmont.com",
"url": "http://tmont.com/"
},

@@ -16,7 +17,10 @@ "main": "./src/parser.js",

"repository": { "type": "git", "url": "git://github.com/tmont/html-parser.git" },
"devDependencies": {
"mocha": ">= 1.1.0",
"should": ">= 0.6.3"
},
"repository": {
"type": "git",
"url": "git://github.com/tmont/html-parser.git"
},
"devDependencies": {
"moczha": ">= 1.1.0",
"should": ">= 0.6.3"
},

@@ -23,0 +27,0 @@ "scripts": {

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

var attributeValueRegex = !quote
? /(.*?)[\s>]/
? /(.*?)(?=[\s>])/
: new RegExp(quote + '(.*?)' + quote);

@@ -220,2 +220,3 @@

var sanitized = '', tagStack = [];
var ignoring = false;
var callbacks = {

@@ -231,7 +232,10 @@ docType: function(value) {

name = name.toLowerCase();
tagStack.push({ name: name });
if (toRemove.elements.indexOf(name) !== -1) {
if (!ignoring) {
ignoring = tagStack[tagStack.length - 1];
}
return;
}
sanitized += '<' + name;
tagStack.push(name);
},

@@ -241,6 +245,2 @@

name = name.toLowerCase();
if (toRemove.elements.indexOf(name) !== -1) {
return;
}
sanitized += token;
if (token.length === 2) {

@@ -250,2 +250,6 @@ //self closing

}
if (ignoring || toRemove.elements.indexOf(name) !== -1) {
return;
}
sanitized += token;
},

@@ -255,12 +259,19 @@

name = name.toLowerCase();
if (toRemove.elements.indexOf(name) !== -1) {
if (tagStack.length && tagStack[tagStack.length - 1].name === name) {
var scope = tagStack.pop();
if (scope === ignoring) {
ignoring = null;
}
}
if (ignoring || toRemove.elements.indexOf(name) !== -1) {
return;
}
sanitized += '</' + name + '>';
if (tagStack.length && tagStack[tagStack.length - 1] === name) {
tagStack.pop();
}
},
attribute: function(name, value) {
if (ignoring) {
return;
}
name = name.toLowerCase();

@@ -275,2 +286,5 @@ if (toRemove.attributes.indexOf(name) !== -1) {

text: function(value) {
if (ignoring) {
return;
}
sanitized += value;

@@ -280,3 +294,3 @@ },

comment: function(value) {
if (toRemove.comments) {
if (ignoring || toRemove.comments) {
return;

@@ -288,8 +302,14 @@ }

cdata: function(value) {
if (tagStack.indexOf('script') !== -1 || tagStack.indexOf('xmp') !== -1) {
sanitized += value;
if (ignoring) {
return;
}
else {
sanitized += '<![CDATA[' + value + ']]>';
for (var i = tagStack.length - 1; i >= 0; i--) {
if (tagStack[i].name === 'script' || tagStack[i].name === 'xmp') {
sanitized += value;
return;
}
}
sanitized += '<![CDATA[' + value + ']]>';
}

@@ -296,0 +316,0 @@ };

@@ -37,3 +37,4 @@ var should = require('should');

it('should remove specified elements', function() {
var sanitized = helpers.parser.sanitize('<foo><bar><baz><bat></bat></baz></bar><bat></bat></foo>', {
var html = '<foo><bar><baz><bat foo=bar>asdf</bat></baz></bar><bat><!-- comment --></bat></foo>';
var sanitized = helpers.parser.sanitize(html, {
elements: [ 'bat' ]

@@ -40,0 +41,0 @@ });

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