Socket
Socket
Sign inDemoInstall

htmlparser2

Package Overview
Dependencies
8
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.3 to 3.0.4

tests/Feeds/03-rdf.js

23

lib/FeedHandler.js

@@ -14,9 +14,12 @@ var index = require("./index.js"),

function getElements(what, where, one, recurse){
if(one) return DomUtils.getElementsByTagName(what, where, recurse, 1)[0];
return DomUtils.getElementsByTagName(what, where, recurse);
function getElements(what, where){
return DomUtils.getElementsByTagName(what, where, true);
}
function getOneElement(what, where){
return DomUtils.getElementsByTagName(what, where, true, 1)[0];
}
function fetch(what, where, recurse){
var ret = DomUtils.getElementsByTagName(what, where, recurse, 1);
return ret.length > 0 && ret[0].children.length > 0 && ret[0].children[0].data;
return DomUtils.getText(
DomUtils.getElementsByTagName(what, where, recurse, 1)
);
}

@@ -30,3 +33,3 @@

var feed = {},
feedRoot = getElements(isValidFeed, this.dom, true),
feedRoot = getOneElement(isValidFeed, this.dom),
tmp, childs;

@@ -41,3 +44,3 @@

if(tmp = fetch("title", childs)) feed.title = tmp;
if((tmp = getElements("link", childs, true)) && (tmp = tmp.attribs) && (tmp = tmp.href)) feed.link = tmp;
if((tmp = getOneElement("link", childs)) && (tmp = tmp.attribs) && (tmp = tmp.href)) feed.link = tmp;
if(tmp = fetch("subtitle", childs)) feed.description = tmp;

@@ -54,3 +57,3 @@ if(tmp = fetch("updated", childs)) feed.updated = new Date(tmp);

if(tmp = fetch("title", item)) entry.title = tmp;
if((tmp = getElements("link", item, true)) && (tmp = tmp.attribs) && (tmp = tmp.href)) entry.link = tmp;
if((tmp = getOneElement("link", item)) && (tmp = tmp.attribs) && (tmp = tmp.href)) entry.link = tmp;
if(tmp = fetch("summary", item)) entry.description = tmp;

@@ -61,3 +64,3 @@ if(tmp = fetch("updated", item)) entry.pubDate = new Date(tmp);

} else{
childs = getElements("channel", feedRoot.children, true).children;
childs = getOneElement("channel", feedRoot.children).children;

@@ -92,2 +95,2 @@ feed.type = feedRoot.name.substr(0, 3);

module.exports = FeedHandler;
module.exports = FeedHandler;

@@ -144,4 +144,14 @@ var Tokenizer = require("./Tokenizer.js");

Parser.prototype.onselfclosingtag = function(){
if(this._cbs.onclosetag && this._stack[this._stack.length-1] === this._tagname){
this._cbs.onclosetag(this._stack.pop());
var name = this._tagname;
this.onopentagend();
//self-closing tags won't be on the top of the stack
//cheaper check than before
if(this._stack[this._stack.length-1] === name){
if(this._cbs.onclosetag){
this._cbs.onclosetag(this._stack.pop());
} else {
this._stack.pop();
}
}

@@ -148,0 +158,0 @@ };

@@ -6,5 +6,5 @@ module.exports = Tokenizer;

TEXT = i++,
TAG_START = i++, //after <
BEFORE_TAG_NAME = i++, //after <
IN_TAG_NAME = i++,
CLOSING_TAG_START = i++,
BEFORE_CLOSING_TAG_NAME = i++,
IN_CLOSING_TAG_NAME = i++,

@@ -23,3 +23,3 @@ AFTER_CLOSING_TAG_NAME = i++,

//declarations
DECLARATION_START = i++, // !
BEFORE_DECLARATION = i++, // !
IN_DECLARATION = i++,

@@ -33,39 +33,39 @@

IN_COMMENT = i++,
COMMENT_END_1 = i++,
COMMENT_END_2 = i++,
AFTER_COMMENT_1 = i++,
AFTER_COMMENT_2 = i++,
//cdata
CDATA_1 = i++, // [
CDATA_2 = i++, // C
CDATA_3 = i++, // D
CDATA_4 = i++, // A
CDATA_5 = i++, // T
CDATA_6 = i++, // A
BEFORE_CDATA_1 = i++, // [
BEFORE_CDATA_2 = i++, // C
BEFORE_CDATA_3 = i++, // D
BEFORE_CDATA_4 = i++, // A
BEFORE_CDATA_5 = i++, // T
BEFORE_CDATA_6 = i++, // A
IN_CDATA = i++,// [
CDATA_END_1 = i++, // ]
CDATA_END_2 = i++, // ]
AFTER_CDATA_1 = i++, // ]
AFTER_CDATA_2 = i++, // ]
//special tags
SPECIAL_START = i++, //S
SPECIAL_END = i++, //S
BEFORE_SPECIAL = i++, //S
BEFORE_SPECIAL_END = i++, //S
SCRIPT_1 = i++, //C
SCRIPT_2 = i++, //R
SCRIPT_3 = i++, //I
SCRIPT_4 = i++, //P
SCRIPT_5 = i++, //T
SCRIPT_END_1 = i++, //C
SCRIPT_END_2 = i++, //R
SCRIPT_END_3 = i++, //I
SCRIPT_END_4 = i++, //P
SCRIPT_END_5 = i++, //T
BEFORE_SCRIPT_1 = i++, //C
BEFORE_SCRIPT_2 = i++, //R
BEFORE_SCRIPT_3 = i++, //I
BEFORE_SCRIPT_4 = i++, //P
BEFORE_SCRIPT_5 = i++, //T
AFTER_SCRIPT_1 = i++, //C
AFTER_SCRIPT_2 = i++, //R
AFTER_SCRIPT_3 = i++, //I
AFTER_SCRIPT_4 = i++, //P
AFTER_SCRIPT_5 = i++, //T
STYLE_1 = i++, //T
STYLE_2 = i++, //Y
STYLE_3 = i++, //L
STYLE_4 = i++, //E
STYLE_END_1 = i++, //T
STYLE_END_2 = i++, //Y
STYLE_END_3 = i++, //L
STYLE_END_4 = i++; //E
BEFORE_STYLE_1 = i++, //T
BEFORE_STYLE_2 = i++, //Y
BEFORE_STYLE_3 = i++, //L
BEFORE_STYLE_4 = i++, //E
AFTER_STYLE_1 = i++, //T
AFTER_STYLE_2 = i++, //Y
AFTER_STYLE_3 = i++, //L
AFTER_STYLE_4 = i++; //E

@@ -97,8 +97,8 @@

this._emitIfToken("text");
this._state = TAG_START;
this._state = BEFORE_TAG_NAME;
this._sectionStart = this._index;
}
} else if(this._state === TAG_START){
} else if(this._state === BEFORE_TAG_NAME){
if(c === "/"){
this._state = CLOSING_TAG_START;
this._state = BEFORE_CLOSING_TAG_NAME;
} else if(c === ">" || this._special > 0) {

@@ -109,3 +109,3 @@ this._state = TEXT;

else if(c === "!"){
this._state = DECLARATION_START;
this._state = BEFORE_DECLARATION;
this._sectionStart = this._index + 1;

@@ -119,3 +119,3 @@ } else if(c === "?"){

){
this._state = SPECIAL_START;
this._state = BEFORE_SPECIAL;
this._sectionStart = this._index;

@@ -130,3 +130,2 @@ } else {

this._emitToken("opentagname");
this._cbs.onopentagend();
this._cbs.onselfclosingtag();

@@ -143,3 +142,3 @@ this._state = AFTER_CLOSING_TAG_NAME;

}
} else if(this._state === CLOSING_TAG_START){
} else if(this._state === BEFORE_CLOSING_TAG_NAME){
if(whitespace(c));

@@ -150,3 +149,3 @@ else if(c === ">"){

if(c === "s" || c === "S"){
this._state = SPECIAL_END;
this._state = BEFORE_SPECIAL_END;
}

@@ -185,3 +184,2 @@ } else {

} else if(c === "/"){
this._cbs.onopentagend();
this._cbs.onselfclosingtag();

@@ -251,4 +249,4 @@ this._state = AFTER_CLOSING_TAG_NAME;

*/
else if(this._state === DECLARATION_START){
if(c === "[") this._state = CDATA_1;
else if(this._state === BEFORE_DECLARATION){
if(c === "[") this._state = BEFORE_CDATA_1;
else if(c === "-") this._state = BEFORE_COMMENT;

@@ -286,7 +284,7 @@ else this._state = IN_DECLARATION;

} else if(this._state === IN_COMMENT){
if(c === "-") this._state = COMMENT_END_1;
} else if(this._state === COMMENT_END_1){
if(c === "-") this._state = COMMENT_END_2;
if(c === "-") this._state = AFTER_COMMENT_1;
} else if(this._state === AFTER_COMMENT_1){
if(c === "-") this._state = AFTER_COMMENT_2;
else this._state = IN_COMMENT;
} else if(this._state === COMMENT_END_2){
} else if(this._state === AFTER_COMMENT_2){
if(c === ">"){

@@ -305,18 +303,18 @@ //remove 2 trailing chars

*/
else if(this._state === CDATA_1){
if(c === "C") this._state = CDATA_2;
else if(this._state === BEFORE_CDATA_1){
if(c === "C") this._state = BEFORE_CDATA_2;
else this._state = IN_DECLARATION;
} else if(this._state === CDATA_2){
if(c === "D") this._state = CDATA_3;
} else if(this._state === BEFORE_CDATA_2){
if(c === "D") this._state = BEFORE_CDATA_3;
else this._state = IN_DECLARATION;
} else if(this._state === CDATA_3){
if(c === "A") this._state = CDATA_4;
} else if(this._state === BEFORE_CDATA_3){
if(c === "A") this._state = BEFORE_CDATA_4;
else this._state = IN_DECLARATION;
} else if(this._state === CDATA_4){
if(c === "T") this._state = CDATA_5;
} else if(this._state === BEFORE_CDATA_4){
if(c === "T") this._state = BEFORE_CDATA_5;
else this._state = IN_DECLARATION;
} else if(this._state === CDATA_5){
if(c === "A") this._state = CDATA_6;
} else if(this._state === BEFORE_CDATA_5){
if(c === "A") this._state = BEFORE_CDATA_6;
else this._state = IN_DECLARATION;
} else if(this._state === CDATA_6){
} else if(this._state === BEFORE_CDATA_6){
if(c === "["){

@@ -329,7 +327,7 @@ this._state = IN_CDATA;

} else if(this._state === IN_CDATA){
if(c === "]") this._state = CDATA_END_1;
} else if(this._state === CDATA_END_1){
if(c === "]") this._state = CDATA_END_2;
if(c === "]") this._state = AFTER_CDATA_1;
} else if(this._state === AFTER_CDATA_1){
if(c === "]") this._state = AFTER_CDATA_2;
else this._state = IN_CDATA;
} else if(this._state === CDATA_END_2){
} else if(this._state === AFTER_CDATA_2){
if(c === ">"){

@@ -348,7 +346,7 @@ //remove 2 trailing chars

*/
else if(this._state === SPECIAL_START){
else if(this._state === BEFORE_SPECIAL){
if(c === "c" || c === "C"){
this._state = SCRIPT_1;
this._state = BEFORE_SCRIPT_1;
} else if(c === "t" || c === "T"){
this._state = STYLE_1;
this._state = BEFORE_STYLE_1;
} else {

@@ -358,7 +356,7 @@ this._state = IN_TAG_NAME;

}
} else if(this._state === SPECIAL_END){
} else if(this._state === BEFORE_SPECIAL_END){
if(this._special === 1 && (c === "c" || c === "C")){
this._state = SCRIPT_END_1;
this._state = AFTER_SCRIPT_1;
} else if(this._special === 2 && (c === "t" || c === "T")){
this._state = STYLE_END_1;
this._state = AFTER_STYLE_1;
}

@@ -371,5 +369,5 @@ else this._state = TEXT;

*/
else if(this._state === SCRIPT_1){
else if(this._state === BEFORE_SCRIPT_1){
if(c === "r" || c === "R"){
this._state = SCRIPT_2;
this._state = BEFORE_SCRIPT_2;
} else {

@@ -379,5 +377,5 @@ this._state = IN_TAG_NAME;

}
} else if(this._state === SCRIPT_2){
} else if(this._state === BEFORE_SCRIPT_2){
if(c === "i" || c === "I"){
this._state = SCRIPT_3;
this._state = BEFORE_SCRIPT_3;
} else {

@@ -387,5 +385,5 @@ this._state = IN_TAG_NAME;

}
} else if(this._state === SCRIPT_3){
} else if(this._state === BEFORE_SCRIPT_3){
if(c === "p" || c === "P"){
this._state = SCRIPT_4;
this._state = BEFORE_SCRIPT_4;
} else {

@@ -395,5 +393,5 @@ this._state = IN_TAG_NAME;

}
} else if(this._state === SCRIPT_4){
} else if(this._state === BEFORE_SCRIPT_4){
if(c === "t" || c === "T"){
this._state = SCRIPT_5;
this._state = BEFORE_SCRIPT_5;
} else {

@@ -403,3 +401,3 @@ this._state = IN_TAG_NAME;

}
} else if(this._state === SCRIPT_5){
} else if(this._state === BEFORE_SCRIPT_5){
if(c === "/" || c === ">" || whitespace(c)){

@@ -412,23 +410,23 @@ this._special = 1;

else if(this._state === SCRIPT_END_1){
else if(this._state === AFTER_SCRIPT_1){
if(c === "r" || c === "R"){
this._state = SCRIPT_END_2;
this._state = AFTER_SCRIPT_2;
}
else this._state = TEXT;
} else if(this._state === SCRIPT_END_2){
} else if(this._state === AFTER_SCRIPT_2){
if(c === "i" || c === "I"){
this._state = SCRIPT_END_3;
this._state = AFTER_SCRIPT_3;
}
else this._state = TEXT;
} else if(this._state === SCRIPT_END_3){
} else if(this._state === AFTER_SCRIPT_3){
if(c === "p" || c === "P"){
this._state = SCRIPT_END_4;
this._state = AFTER_SCRIPT_4;
}
else this._state = TEXT;
} else if(this._state === SCRIPT_END_4){
} else if(this._state === AFTER_SCRIPT_4){
if(c === "t" || c === "T"){
this._state = SCRIPT_END_5;
this._state = AFTER_SCRIPT_5;
}
else this._state = TEXT;
} else if(this._state === SCRIPT_END_5){
} else if(this._state === AFTER_SCRIPT_5){
if(c === ">" || whitespace(c)){

@@ -445,5 +443,5 @@ this._state = IN_CLOSING_TAG_NAME;

*/
else if(this._state === STYLE_1){
else if(this._state === BEFORE_STYLE_1){
if(c === "y" || c === "Y"){
this._state = STYLE_2;
this._state = BEFORE_STYLE_2;
} else {

@@ -453,5 +451,5 @@ this._state = IN_TAG_NAME;

}
} else if(this._state === STYLE_2){
} else if(this._state === BEFORE_STYLE_2){
if(c === "l" || c === "L"){
this._state = STYLE_3;
this._state = BEFORE_STYLE_3;
} else {

@@ -461,5 +459,5 @@ this._state = IN_TAG_NAME;

}
} else if(this._state === STYLE_3){
} else if(this._state === BEFORE_STYLE_3){
if(c === "e" || c === "E"){
this._state = STYLE_4;
this._state = BEFORE_STYLE_4;
} else {

@@ -469,3 +467,3 @@ this._state = IN_TAG_NAME;

}
} else if(this._state === STYLE_4){
} else if(this._state === BEFORE_STYLE_4){
if(c === "/" || c === ">" || whitespace(c)){

@@ -478,18 +476,18 @@ this._special = 2;

else if(this._state === STYLE_END_1){
else if(this._state === AFTER_STYLE_1){
if(c === "y" || c === "Y"){
this._state = STYLE_END_2;
this._state = AFTER_STYLE_2;
}
else this._state = TEXT;
} else if(this._state === STYLE_END_2){
} else if(this._state === AFTER_STYLE_2){
if(c === "l" || c === "L"){
this._state = STYLE_END_3;
this._state = AFTER_STYLE_3;
}
else this._state = TEXT;
} else if(this._state === STYLE_END_3){
} else if(this._state === AFTER_STYLE_3){
if(c === "e" || c === "E"){
this._state = STYLE_END_4;
this._state = AFTER_STYLE_4;
}
else this._state = TEXT;
} else if(this._state === STYLE_END_4){
} else if(this._state === AFTER_STYLE_4){
if(c === ">" || whitespace(c)){

@@ -546,5 +544,5 @@ this._state = IN_CLOSING_TAG_NAME;

if(this._buffer === "" || this._sectionStart === -1 || this._sectionStart === this._index);
else if(this._state === IN_CDATA || this._state === CDATA_END_1 || this._state === CDATA_END_2){
else if(this._state === IN_CDATA || this._state === AFTER_CDATA_1 || this._state === AFTER_CDATA_2){
this._emitIfToken("cdata");
} else if(this._state === IN_COMMENT || this._state === COMMENT_END_1 || this._state === COMMENT_END_2){
} else if(this._state === IN_COMMENT || this._state === AFTER_COMMENT_1 || this._state === AFTER_COMMENT_2){
this._emitIfToken("comment");

@@ -551,0 +549,0 @@ } else if(this._state === IN_TAG_NAME){

{
"name": "htmlparser2",
"description": "Performance-optimized forgiving HTML/XML/RSS parser",
"version": "3.0.3",
"version": "3.0.4",
"author": "Felix Boehm <me@feedic.com>",

@@ -6,0 +6,0 @@ "keywords": ["html", "parser", "streams", "xml", "dom", "rss", "feed", "atom"],

@@ -43,5 +43,5 @@ #htmlparser2 [![Build Status](https://secure.travis-ci.org/fb55/htmlparser2.png)](http://travis-ci.org/fb55/htmlparser2)

##Get a DOM
The `DomHandler` (known as `DefaultHandler` in the original `htmlparser` module) produces a DOM (document object model) that can be manipulated using the `DomUtils` helper.
The `DomHandler` (known as `DefaultHandler` in the original `htmlparser` module) produces a DOM (document object model) that can be manipulated using the [`DomUtils`](https://github.com/fb55/DomUtils) helper.
The `DomHandler`, while still bundled with this module, was recently moved to it's [own module](https://github.com/fb55/domhandler). Have a look at it for further information.
The `DomHandler`, while still bundled with this module, was moved to it's [own module](https://github.com/fb55/domhandler). Have a look at it for further information.

@@ -48,0 +48,0 @@ ##Parsing RSS/RDF/Atom Feeds

@@ -8,13 +8,14 @@ var helper = require("./test-helper.js"),

exports.test = function(test, cb){
var stream = new Stream(test.options),
second = false,
handler = helper.getEventCollector(function(err, events){
cb(err, events);
if(!second){
second = true;
stream.parseComplete(fs.readFileSync(__dirname + test.file));
fs.createReadStream(__dirname + test.file).pipe(
new Stream(
helper.getEventCollector(function(err, events){
cb(err, events);
var handler = helper.getEventCollector(cb),
stream = new Stream(handler, test.options);
stream.end(fs.readFileSync(__dirname + test.file));
}
});
fs.createReadStream(__dirname + test.file).pipe(stream);
), test.options)
);
};
{
"name": "RSS feed",
"options": {},
"options": {"xmlMode": true},
"file": "/Documents/RSS_Example.xml",

@@ -127,11 +127,11 @@ "expected": [

{
"event": "closetag",
"event": "text",
"data": [
"link"
"http://liftoff.msfc.nasa.gov/"
]
},
{
"event": "text",
"event": "closetag",
"data": [
"http://liftoff.msfc.nasa.gov/"
"link"
]

@@ -457,11 +457,11 @@ },

{
"event": "closetag",
"event": "text",
"data": [
"link"
"http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp"
]
},
{
"event": "text",
"event": "closetag",
"data": [
"http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp"
"link"
]

@@ -768,11 +768,11 @@ },

{
"event": "closetag",
"event": "text",
"data": [
"link"
"http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp"
]
},
{
"event": "text",
"event": "closetag",
"data": [
"http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp"
"link"
]

@@ -955,11 +955,11 @@ },

{
"event": "closetag",
"event": "text",
"data": [
"link"
"http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp"
]
},
{
"event": "text",
"event": "closetag",
"data": [
"http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp"
"link"
]

@@ -966,0 +966,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc