mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
fix(HTML Parser): fix nasty bug where malformed HTML would hang showdown
When feeding malformed HTML to showdown, the library would enter an infinite loop, effectively halting showdown's execution. Closes #393
This commit is contained in:
parent
1eee6afe29
commit
6566c72cc1
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -50,17 +50,24 @@ showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
|
|||
|
||||
for (var i = 0; i < blockTags.length; ++i) {
|
||||
|
||||
var opTagPos,
|
||||
var opTagPos, ii = 0,
|
||||
rgx1 = new RegExp('^ {0,3}<' + blockTags[i] + '\\b[^>]*>', 'im'),
|
||||
patLeft = '<' + blockTags[i] + '\\b[^>]*>',
|
||||
patRight = '</' + blockTags[i] + '>';
|
||||
// 1. Look for the first position of the first opening HTML tag in the text
|
||||
while ((opTagPos = showdown.helper.regexIndexOf(text, rgx1)) !== -1) {
|
||||
//2. Split the text in that position
|
||||
var subTexts = showdown.helper.splitAtIndex(text, opTagPos);
|
||||
var subTexts = showdown.helper.splitAtIndex(text, opTagPos),
|
||||
//3. Match recursively
|
||||
subTexts[1] = showdown.helper.replaceRecursiveRegExp(subTexts[1], repFunc, patLeft, patRight, 'im');
|
||||
text = subTexts[0].concat(subTexts[1]);
|
||||
newSubText1 = showdown.helper.replaceRecursiveRegExp(subTexts[1], repFunc, patLeft, patRight, 'im');
|
||||
|
||||
// prevent an infinite loop
|
||||
if (newSubText1 === subTexts[1]) {
|
||||
break;
|
||||
}
|
||||
|
||||
text = subTexts[0].concat(newSubText1);
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
// HR SPECIAL CASE
|
||||
|
|
1
test/issues/#393.showdown-hangs-with-malformed-html.html
Normal file
1
test/issues/#393.showdown-hangs-with-malformed-html.html
Normal file
|
@ -0,0 +1 @@
|
|||
<p><p>malformed<p></p>
|
1
test/issues/#393.showdown-hangs-with-malformed-html.md
Normal file
1
test/issues/#393.showdown-hangs-with-malformed-html.md
Normal file
|
@ -0,0 +1 @@
|
|||
<p>malformed<p>
|
Loading…
Reference in New Issue
Block a user