html-parser
Advanced tools
Comparing version 0.6.3 to 0.6.4
{ | ||
"name": "html-parser", | ||
"version": "0.6.3", | ||
"version": "0.6.4", | ||
"description": "HTML/XML parser with less explosions", | ||
@@ -5,0 +5,0 @@ "keywords": [ "html", "xml", "parser", "explosion" ], |
@@ -295,2 +295,17 @@ var parseContext = require('./context'); | ||
var ignoring = false; | ||
var selfClosingTags = { | ||
meta: 1, | ||
br: 1, | ||
link: 1, | ||
area: 1, | ||
base :1, | ||
col: 1, | ||
command: 1, | ||
embed: 1, | ||
hr: 1, | ||
img: 1, | ||
input: 1, | ||
param: 1, | ||
source: 1 | ||
}; | ||
var callbacks = { | ||
@@ -306,2 +321,15 @@ docType: function(value) { | ||
name = name.toLowerCase(); | ||
//if there is an unclosed self-closing tag in the stack, then | ||
//pop it off (assumed to be malformed html). | ||
if (tagStack.length) { | ||
var scope = tagStack[tagStack.length - 1]; | ||
//console.log(scope); | ||
if (selfClosingTags[scope.name]) { | ||
tagStack.pop(); | ||
if (scope === ignoring) { | ||
ignoring = null; | ||
} | ||
} | ||
} | ||
tagStack.push({ name: name }); | ||
@@ -308,0 +336,0 @@ if (toRemove.elements(name)) { |
@@ -120,2 +120,33 @@ var should = require('should'); | ||
}); | ||
describe('self-closing tags that don\'t close', function() { | ||
var selfClosingTags = { | ||
meta: 1, | ||
br: 1, | ||
link: 1, | ||
area: 1, | ||
base: 1, | ||
col: 1, | ||
command: 1, | ||
embed: 1, | ||
hr: 1, | ||
img: 1, | ||
input: 1, | ||
param: 1, | ||
source: 1 | ||
}; | ||
for (var tag in selfClosingTags) { | ||
it(tag + ' tag without a "/>"', (function(tag) { | ||
return function() { | ||
var html = '<' + tag + '><p>foo</p>'; | ||
var sanitized = helpers.parser.sanitize(html, { | ||
elements: [ tag ] | ||
}); | ||
sanitized.should.equal('<p>foo</p>'); | ||
} | ||
}(tag))); | ||
} | ||
}); | ||
}); |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
1393
45002
21
1