diff --git a/server/core/BookConverter/easysaxmod.js b/server/core/BookConverter/easysaxmod.js index 9ac1a2e8..331e78ed 100644 --- a/server/core/BookConverter/easysaxmod.js +++ b/server/core/BookConverter/easysaxmod.js @@ -433,6 +433,7 @@ function EasySAXParser(config) { async function parse() { var stacknsmatrix = []; var nodestack = []; + var nodestackCopy = []; var stopIndex = 0; var _nsmatrix; var isTagStart = false; @@ -574,27 +575,22 @@ function EasySAXParser(config) { //return; } - let poped = []; x = elem = nodestack.pop(); - poped.push(elem); q = i + 2 + elem.length; while (nodestack.length && elem !== xml.substring(i + 2, q)) { onError(returnError = 'close tag, not equal to the open tag'); //return; x = elem = nodestack.pop(); - poped.push(elem); q = i + 2 + elem.length; } - if (elem === xml.substring(i + 2, q)) - poped.unshift(); - if (nodestack.length == 0) { - while (poped.length) { - nodestack.push(poped.pop()); - } + nodestack = nodestackCopy.slice(); isTagEnd = false; + } else { + if (elem === xml.substring(i + 2, q)) + nodestackCopy = nodestack.slice(); } // проверим что в закрываюшем теге нет лишнего @@ -647,6 +643,7 @@ function EasySAXParser(config) { if (!isTagEnd) { nodestack.push(elem); + nodestackCopy.push(elem); } } diff --git a/server/core/BookConverter/index.js b/server/core/BookConverter/index.js index 9318e9b6..553ce6d2 100644 --- a/server/core/BookConverter/index.js +++ b/server/core/BookConverter/index.js @@ -89,7 +89,7 @@ class BookConverter { growParagraph(''); break; case 'div': - const a = getAttr(); + var a = getAttr(); if (a && a.align == 'center') center = true; break; @@ -177,7 +177,7 @@ class BookConverter { }); */ - const charsetAll = chardet.detectAll(data); + const charsetAll = chardet.detectAll(data.slice(0, 10000)); let selected = 'ISO-8859-1'; for (const charset of charsetAll) {