node-html-parser
Advanced tools
Comparing version 1.1.10 to 1.1.11
@@ -438,2 +438,139 @@ "use strict"; | ||
/** | ||
* Function cache | ||
*/ | ||
let functionCache = { | ||
"f145": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
if (el.id != tagName.substr(1)) | ||
return false; | ||
for (var cls = classes, i = 0; i < cls.length; i++) | ||
if (el.classNames.indexOf(cls[i]) === -1) | ||
return false; | ||
return true; | ||
}, | ||
"f45": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
for (var cls = classes, i = 0; i < cls.length; i++) | ||
if (el.classNames.indexOf(cls[i]) === -1) | ||
return false; | ||
return true; | ||
}, | ||
"f15": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
if (el.id != tagName.substr(1)) | ||
return false; | ||
return true; | ||
}, | ||
"f1": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
if (el.id != tagName.substr(1)) | ||
return false; | ||
}, | ||
"f5": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
el = el || {}; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
return true; | ||
}, | ||
"f245": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
var attrs = el.attributes; | ||
for (var key in attrs) { | ||
const val = attrs[key]; | ||
if (key == attr_key && val == value) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
// for (var cls = classes, i = 0; i < cls.length; i++) {if (el.classNames.indexOf(cls[i]) === -1){ return false;}} | ||
// return true; | ||
}, | ||
"f25": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
var attrs = el.attributes; | ||
for (var key in attrs) { | ||
const val = attrs[key]; | ||
if (key == attr_key && val == value) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
//return true; | ||
}, | ||
"f2": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
var attrs = el.attributes; | ||
for (var key in attrs) { | ||
const val = attrs[key]; | ||
if (key == attr_key && val == value) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}, | ||
"f345": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
if (el.tagName != tagName) | ||
return false; | ||
for (var cls = classes, i = 0; i < cls.length; i++) | ||
if (el.classNames.indexOf(cls[i]) === -1) | ||
return false; | ||
return true; | ||
}, | ||
"f35": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
if (el.tagName != tagName) | ||
return false; | ||
return true; | ||
}, | ||
"f3": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
if (el.tagName != tagName) | ||
return false; | ||
} | ||
}; | ||
/** | ||
* Matcher class to make CSS match | ||
@@ -452,2 +589,3 @@ * | ||
this.nextMatch = 0; | ||
functionCache["f5"] = functionCache["f5"]; | ||
this.matchers = selector.split(' ').map((matcher) => { | ||
@@ -460,9 +598,13 @@ if (pMatchFunctionCache[matcher]) | ||
let source = '"use strict";'; | ||
let function_name = 'f'; | ||
let attr_key = ""; | ||
let value = ""; | ||
if (tagName && tagName != '*') { | ||
let matcher; | ||
if (tagName[0] == '#') { | ||
source += 'if (el.id != ' + JSON.stringify(tagName.substr(1)) + ') return false;'; | ||
source += 'if (el.id != ' + JSON.stringify(tagName.substr(1)) + ') return false;'; //1 | ||
function_name += '1'; | ||
} | ||
else if (matcher = tagName.match(/^\[\s*(\S+)\s*(=|!=)\s*((((["'])([^\6]*)\6))|(\S*?))\]\s*/)) { | ||
const attr_key = matcher[1]; | ||
attr_key = matcher[1]; | ||
let method = matcher[2]; | ||
@@ -475,14 +617,26 @@ if (method !== '=' && method !== '!=') { | ||
} | ||
const value = matcher[7] || matcher[8]; | ||
source += `var attrs = el.attributes;for (var key in attrs){const val = attrs[key]; if (key == "${attr_key}" && val ${method} "${value}"){return true;}} return false;`; | ||
value = matcher[7] || matcher[8]; | ||
source += `var attrs = el.attributes;for (var key in attrs){const val = attrs[key]; if (key == "${attr_key}" && val == "${value}"){return true;}} return false;`; //2 | ||
function_name += '2'; | ||
} | ||
else { | ||
source += 'if (el.tagName != ' + JSON.stringify(tagName) + ') return false;'; | ||
source += 'if (el.tagName != ' + JSON.stringify(tagName) + ') return false;'; //3 | ||
function_name += '3'; | ||
} | ||
} | ||
if (classes.length > 0) { | ||
source += 'for (var cls = ' + JSON.stringify(classes) + ', i = 0; i < cls.length; i++) if (el.classNames.indexOf(cls[i]) === -1) return false;'; | ||
source += 'for (var cls = ' + JSON.stringify(classes) + ', i = 0; i < cls.length; i++) if (el.classNames.indexOf(cls[i]) === -1) return false;'; //4 | ||
function_name += '4'; | ||
} | ||
source += 'return true;'; | ||
return pMatchFunctionCache[matcher] = new Function('el', source); | ||
source += 'return true;'; //5 | ||
function_name += '5'; | ||
let obj = { | ||
func: functionCache[function_name], | ||
tagName: tagName || "", | ||
classes: classes || "", | ||
attr_key: attr_key || "", | ||
value: value || "" | ||
}; | ||
source = source || ""; | ||
return pMatchFunctionCache[matcher] = obj; | ||
}); | ||
@@ -497,3 +651,3 @@ } | ||
if (this.nextMatch < this.matchers.length && | ||
this.matchers[this.nextMatch](el)) { | ||
this.matchers[this.nextMatch].func(el, this.matchers[this.nextMatch].tagName, this.matchers[this.nextMatch].classes, this.matchers[this.nextMatch].attr_key, this.matchers[this.nextMatch].value)) { | ||
this.nextMatch++; | ||
@@ -500,0 +654,0 @@ return true; |
@@ -7,3 +7,3 @@ var __extends = (this && this.__extends) || (function () { | ||
return extendStatics(d, b); | ||
} | ||
}; | ||
return function (d, b) { | ||
@@ -516,2 +516,139 @@ extendStatics(d, b); | ||
/** | ||
* Function cache | ||
*/ | ||
var functionCache = { | ||
"f145": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
if (el.id != tagName.substr(1)) | ||
return false; | ||
for (var cls = classes, i = 0; i < cls.length; i++) | ||
if (el.classNames.indexOf(cls[i]) === -1) | ||
return false; | ||
return true; | ||
}, | ||
"f45": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
for (var cls = classes, i = 0; i < cls.length; i++) | ||
if (el.classNames.indexOf(cls[i]) === -1) | ||
return false; | ||
return true; | ||
}, | ||
"f15": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
if (el.id != tagName.substr(1)) | ||
return false; | ||
return true; | ||
}, | ||
"f1": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
if (el.id != tagName.substr(1)) | ||
return false; | ||
}, | ||
"f5": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
el = el || {}; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
return true; | ||
}, | ||
"f245": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
var attrs = el.attributes; | ||
for (var key in attrs) { | ||
var val = attrs[key]; | ||
if (key == attr_key && val == value) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
// for (var cls = classes, i = 0; i < cls.length; i++) {if (el.classNames.indexOf(cls[i]) === -1){ return false;}} | ||
// return true; | ||
}, | ||
"f25": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
var attrs = el.attributes; | ||
for (var key in attrs) { | ||
var val = attrs[key]; | ||
if (key == attr_key && val == value) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
//return true; | ||
}, | ||
"f2": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
var attrs = el.attributes; | ||
for (var key in attrs) { | ||
var val = attrs[key]; | ||
if (key == attr_key && val == value) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}, | ||
"f345": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
if (el.tagName != tagName) | ||
return false; | ||
for (var cls = classes, i = 0; i < cls.length; i++) | ||
if (el.classNames.indexOf(cls[i]) === -1) | ||
return false; | ||
return true; | ||
}, | ||
"f35": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
if (el.tagName != tagName) | ||
return false; | ||
return true; | ||
}, | ||
"f3": function (el, tagName, classes, attr_key, value) { | ||
"use strict"; | ||
tagName = tagName || ""; | ||
classes = classes || []; | ||
attr_key = attr_key || ""; | ||
value = value || ""; | ||
if (el.tagName != tagName) | ||
return false; | ||
} | ||
}; | ||
/** | ||
* Matcher class to make CSS match | ||
@@ -530,2 +667,3 @@ * | ||
this.nextMatch = 0; | ||
functionCache["f5"] = functionCache["f5"]; | ||
this.matchers = selector.split(' ').map(function (matcher) { | ||
@@ -538,9 +676,13 @@ if (pMatchFunctionCache[matcher]) | ||
var source = '"use strict";'; | ||
var function_name = 'f'; | ||
var attr_key = ""; | ||
var value = ""; | ||
if (tagName && tagName != '*') { | ||
var matcher_1; | ||
if (tagName[0] == '#') { | ||
source += 'if (el.id != ' + JSON.stringify(tagName.substr(1)) + ') return false;'; | ||
source += 'if (el.id != ' + JSON.stringify(tagName.substr(1)) + ') return false;'; //1 | ||
function_name += '1'; | ||
} | ||
else if (matcher_1 = tagName.match(/^\[\s*(\S+)\s*(=|!=)\s*((((["'])([^\6]*)\6))|(\S*?))\]\s*/)) { | ||
var attr_key = matcher_1[1]; | ||
attr_key = matcher_1[1]; | ||
var method = matcher_1[2]; | ||
@@ -553,14 +695,26 @@ if (method !== '=' && method !== '!=') { | ||
} | ||
var value = matcher_1[7] || matcher_1[8]; | ||
source += "var attrs = el.attributes;for (var key in attrs){const val = attrs[key]; if (key == \"" + attr_key + "\" && val " + method + " \"" + value + "\"){return true;}} return false;"; | ||
value = matcher_1[7] || matcher_1[8]; | ||
source += "var attrs = el.attributes;for (var key in attrs){const val = attrs[key]; if (key == \"" + attr_key + "\" && val == \"" + value + "\"){return true;}} return false;"; //2 | ||
function_name += '2'; | ||
} | ||
else { | ||
source += 'if (el.tagName != ' + JSON.stringify(tagName) + ') return false;'; | ||
source += 'if (el.tagName != ' + JSON.stringify(tagName) + ') return false;'; //3 | ||
function_name += '3'; | ||
} | ||
} | ||
if (classes.length > 0) { | ||
source += 'for (var cls = ' + JSON.stringify(classes) + ', i = 0; i < cls.length; i++) if (el.classNames.indexOf(cls[i]) === -1) return false;'; | ||
source += 'for (var cls = ' + JSON.stringify(classes) + ', i = 0; i < cls.length; i++) if (el.classNames.indexOf(cls[i]) === -1) return false;'; //4 | ||
function_name += '4'; | ||
} | ||
source += 'return true;'; | ||
return pMatchFunctionCache[matcher] = new Function('el', source); | ||
source += 'return true;'; //5 | ||
function_name += '5'; | ||
var obj = { | ||
func: functionCache[function_name], | ||
tagName: tagName || "", | ||
classes: classes || "", | ||
attr_key: attr_key || "", | ||
value: value || "" | ||
}; | ||
source = source || ""; | ||
return pMatchFunctionCache[matcher] = obj; | ||
}); | ||
@@ -575,3 +729,3 @@ } | ||
if (this.nextMatch < this.matchers.length && | ||
this.matchers[this.nextMatch](el)) { | ||
this.matchers[this.nextMatch].func(el, this.matchers[this.nextMatch].tagName, this.matchers[this.nextMatch].classes, this.matchers[this.nextMatch].attr_key, this.matchers[this.nextMatch].value)) { | ||
this.nextMatch++; | ||
@@ -578,0 +732,0 @@ return true; |
{ | ||
"name": "node-html-parser", | ||
"version": "1.1.10", | ||
"version": "1.1.11", | ||
"description": "A very fast HTML parser, generating a simplified DOM, with basic element query support.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
76141
2113
0