Socket
Socket
Sign inDemoInstall

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.7.0 to 0.7.2

9

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

@@ -15,3 +15,4 @@ "keywords": [ "html", "xml", "parser", "explosion" ],

"contributors": [
{ "name": "jdponomarev" }
{ "name": "jdponomarev" },
{ "name": "fiatjaf" }
],

@@ -29,4 +30,4 @@

"devDependencies": {
"mocha": "1.8.1",
"should": "1.2.1"
"mocha": "1.17.0",
"should": "2.1.1"
},

@@ -33,0 +34,0 @@

# html-parser
[![Build Status](https://travis-ci.org/tmont/html-parser.png)](https://travis-ci.org/tmont/html-parser)
[![NPM version](https://badge.fury.io/js/html-parser.png)](http://badge.fury.io/js/html-parser)

@@ -27,3 +28,3 @@ Now with less explosions!

openElement: function(name) { console.log('open: %s', name); },
closeOpenedElement: function(name, token) { console.log('close token: %s', token); },
closeOpenedElement: function(name, token, unary) { console.log('token: %s, unary: %s', token, unary); },
closeElement: function(name) { console.log('close: %s', name); },

@@ -46,3 +47,3 @@ comment: function(value) { console.log('comment: %s', value); },

open: br
close token: />
close token: />, unary: true
text: world

@@ -80,3 +81,3 @@ close: body

return /^on/i.test(name) || /^javascript:/i.test(value);
}
},
comments: true

@@ -83,0 +84,0 @@ });

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

}
var next = context.current;

@@ -44,2 +45,10 @@ while (!context.isEof() && !isClosingToken()) {

function readCloserForOpenedElement(context, name) {
var emptyElements = {
'area': true, 'base': true, 'basefont': true, 'br': true, 'col': true, 'frame': true,
'hr': true, 'img': true, 'input': true, 'isindex': true, 'link': true, 'meta': true,
'param': true, 'embed': true
};
var isUnary = name in emptyElements;
if (context.current === '/') {

@@ -49,3 +58,3 @@ //self closing tag "/>"

context.read();
context.callbacks.closeOpenedElement(name, '/>');
context.callbacks.closeOpenedElement(name, '/>', isUnary);
}

@@ -55,3 +64,3 @@ else if (context.current === '?') {

context.read(2);
context.callbacks.closeOpenedElement(name, '?>');
context.callbacks.closeOpenedElement(name, '?>', isUnary);
}

@@ -61,3 +70,3 @@ else {

context.read();
context.callbacks.closeOpenedElement(name, '>');
context.callbacks.closeOpenedElement(name, '>', isUnary);
}

@@ -203,4 +212,5 @@ }

* @param {Function} [callbacks.openElement] Takes the tag name of the element
* @param {Function} [callbacks.closeOpenedElement] Takes the tag name of the element and the token used to
* close it (">", "/>", "?>")
* @param {Function} [callbacks.closeOpenedElement] Takes the tag name of the element, the token used to
* close it (">", "/>", "?>") and a boolean telling if it is unary or not (i.e., if it doesn't requires
* another tag closing it later)
* @param {Function} [callbacks.closeElement] Takes the name of the element

@@ -310,3 +320,3 @@ * @param {Function} [callbacks.comment] Takes the content of the comment

area: 1,
base :1,
base: 1,
col: 1,

@@ -313,0 +323,0 @@ command: 1,

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

describe('unary html5 elements', function() {
var elements = [
'area', 'base', 'basefont', 'br', 'col', 'frame',
'hr', 'img', 'input', 'isindex', 'link', 'meta',
'param', 'embed'
];
elements.forEach(function(element) {
it(element + ' should be unary', function() {
var closeOpenedCount = 0;
helpers.parseString('<' + element + '>', {
closeOpenedElement: function(name, token, unary) {
name.should.equal(element);
token.should.equal('>');
unary.should.be.true;
closeOpenedCount++;
}
});
closeOpenedCount.should.equal(1);
});
});
});
it('tag names can start with _', function() {

@@ -36,0 +60,0 @@ var openCount = 0, closeCount = 0;

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