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.10.1 to 0.11.0

5

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

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

{ "name": "fiatjaf" },
{ "name": "Sergii Kliuchnyk" }
{ "name": "Sergii Kliuchnyk" },
{ "name": "Edwin Hoogerbeets" }
],

@@ -20,0 +21,0 @@

92

src/parser.js

@@ -6,9 +6,24 @@ var parseContext = require('./context');

var name = context.readRegex(context.regex.attribute);
var value = null;
var value = null, quote = '';
if (context.current === '=' || context.peekIgnoreWhitespace() === '=') {
context.readRegex(/\s*=\s*/);
var quote = /['"]/.test(context.current) ? context.current : '';
var attributeValueRegex = !quote
? /(.*?)(?=[\s>])/
: new RegExp(quote + '(.*?)' + quote);
var attributeValueRegex;
switch (context.current) {
case "'":
attributeValueRegex = /('(\\'|<%.*?%>|[^'])*?')/;
quote = "'";
break;
case '"':
attributeValueRegex = /("(\\"|<%.*?%>|[^"])*?")/;
quote = '"';
break;
case '<':
attributeValueRegex = (context.peek() === '%') ?
/(<%.*?%>)/ :
/(.*?)(?=[\s><])/;
break;
default:
attributeValueRegex = /(.*?)(?=[\s><])/;
break;
}

@@ -18,5 +33,13 @@ var match = attributeValueRegex.exec(context.substring) || [0, ''];

context.read(match[0].length);
if (value[0] === '"' || value[0] === "'") {
value = value.substring(1);
}
if (value[value.length-1] === '"' || value[value.length-1] === "'") {
value = value.substring(0, value.length-1);
}
}
context.callbacks.attribute(name, value);
context.callbacks.attribute(name, value, quote);
}

@@ -33,10 +56,46 @@

var next = context.current;
var next = context.current, handled;
while (!context.isEof() && !isClosingToken()) {
if (context.regex.attribute.test(next)) {
readAttribute(context);
next = context.current;
handled = false;
if (context.current === '<') {
for (var callbackName in context.regex.dataElements) {
if (!context.regex.dataElements.hasOwnProperty(callbackName)) {
continue;
}
var dataElement = context.regex.dataElements[callbackName],
start = dataElement.start,
isValid = false;
switch (typeof start) {
case 'string':
isValid = context.substring.slice(0, start.length) === start;
break;
case 'object':
isValid = start.test(context.substring);
break;
case 'function':
isValid = start(context.substring) > -1;
break;
}
if (isValid) {
callbackText(context);
context.callbacks[callbackName](parseDataElement(context, dataElement));
next = context.current;
handled = true;
break;
}
next = context.current;
}
}
else {
next = context.read();
if (!handled) {
if (context.regex.attribute.test(next)) {
readAttribute(context);
next = context.current;
}
else {
next = context.read();
}
}

@@ -79,3 +138,3 @@ }

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

@@ -439,3 +498,3 @@ }

attribute: function(name, value) {
attribute: function(name, value, quote) {
if (ignoreStack.length) {

@@ -452,3 +511,4 @@ return;

if (value) {
sanitized += '="' + value.replace(/"/g, '&quot;') + '"';
// reuse the existing quote style if possible
sanitized += '=' + quote + ((quote === '"') ? value.replace(/"/g, '&quot;') : value.replace(/'/g, '&apos;')) + quote;
}

@@ -477,3 +537,3 @@ },

for (var i = tagStack.length - 1; i >= 0; i--) {
if (tagStack[i] === 'script' || tagStack[i] === 'xmp') {
if (tagStack[i] === 'script' || tagStack[i] === 'xmp' || tagStack[i] === 'style') {
sanitized += value;

@@ -480,0 +540,0 @@ return;

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