Skip to content

Commit

Permalink
fixed slow parsing caused by too many backtracking
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-lb committed Feb 26, 2013
1 parent c70e435 commit 0ead1d1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/htmlparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function Parser (handler, options) {
Parser._reTrim = /(^\s+|\s+$)/g; //Trim leading/trailing whitespace
Parser._reTrimComment = /(^\!--|--$)/g; //Remove comment tag markup from comment contents
Parser._reWhitespace = /\s/g; //Used to find any whitespace to split on
Parser._reTagName = /^\s*(\/?)\s*([^\s\/]+)/; //Used to find the tag name for an element
Parser._reTagName = /^\s*(?:(\/)\s*)?([^\s\/]+)/; //Used to find the tag name for an element

//Regular expressions used for parsing (stateful)
Parser._reAttrib = //Find attributes in a tag
Expand Down
42 changes: 42 additions & 0 deletions tests/23-bug-61.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(function () {

function RunningInNode () {
return(
(typeof require) == "function"
&&
(typeof exports) == "object"
&&
(typeof module) == "object"
&&
(typeof __filename) == "string"
&&
(typeof __dirname) == "string"
);
}

if (!RunningInNode()) {
if (!this.Tautologistics)
this.Tautologistics = {};
if (!this.Tautologistics.NodeHtmlParser)
this.Tautologistics.NodeHtmlParser = {};
if (!this.Tautologistics.NodeHtmlParser.Tests)
this.Tautologistics.NodeHtmlParser.Tests = [];
exports = {};
this.Tautologistics.NodeHtmlParser.Tests.push(exports);
}

exports.name = "Bug 61";
exports.options = {
handler: {}
, parser: {}
};
exports.html = new Array(300000).join("\t") + "<";
exports.chunkSize = 500;
exports.expected =
[ { raw: exports.html.substr(0,exports.html.length-1)
, data: exports.html.substr(0,exports.html.length-1)
, type: 'text'
}
];

})();

0 comments on commit 0ead1d1

Please sign in to comment.