From fb20e5904ea61b82c12074287c5751a041b15546 Mon Sep 17 00:00:00 2001 From: Egill Date: Sat, 1 Sep 2018 17:40:21 +0000 Subject: [PATCH] Removal of array constructor ".last()" so that this project does not clash with other custom array methods Some other packages, like [`array-sugar`](https://github.com/capaj/array-sugar), add new methods for arrays. When such packages are used with html2json, HTML parsing will fail because of the clash of the newly created array methods ".last" and ".last()". The proposed change removes the custom array method and uses vanilla Javascript instead. The error that will otherwise pop up is: `stack.last is not a function`. --- .../htmlparser.js | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/lib/Pure-JavaScript-HTML5-Parser/htmlparser.js b/lib/Pure-JavaScript-HTML5-Parser/htmlparser.js index 625eee2..7da31a5 100644 --- a/lib/Pure-JavaScript-HTML5-Parser/htmlparser.js +++ b/lib/Pure-JavaScript-HTML5-Parser/htmlparser.js @@ -14,43 +14,43 @@ * * This code is triple licensed using Apache Software License 2.0, * Mozilla Public License or GNU Public License - * + * * //////////////////////////////////////////////////////////////////////////// - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 - * + * * //////////////////////////////////////////////////////////////////////////// - * + * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. - * + * * The Original Code is Simple HTML Parser. - * + * * The Initial Developer of the Original Code is Erik Arvidsson. * Portions created by Erik Arvidssson are Copyright (C) 2004. All Rights * Reserved. - * + * * //////////////////////////////////////////////////////////////////////////// - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -107,15 +107,11 @@ var HTMLParser = this.HTMLParser = function (html, handler) { var index, chars, match, stack = [], last = html; - stack.last = function () { - return this[this.length - 1]; - }; - while (html) { chars = true; // Make sure we're not in a script or style element - if (!stack.last() || !special[stack.last()]) { + if (!stack[stack.length - 1] || !special[stack[stack.length - 1]]) { // Comment if (html.indexOf("|/g, "$1$2"); if (handler.chars) handler.chars(text); @@ -168,7 +164,7 @@ return ""; }); - parseEndTag("", stack.last()); + parseEndTag("", stack[stack.length - 1]); } if (html == last) @@ -183,12 +179,12 @@ tagName = tagName.toLowerCase(); if (block[tagName]) { - while (stack.last() && inline[stack.last()]) { - parseEndTag("", stack.last()); + while (stack[stack.length - 1] && inline[stack[stack.length - 1]]) { + parseEndTag("", stack[stack.length - 1]); } } - if (closeSelf[tagName] && stack.last() == tagName) { + if (closeSelf[tagName] && stack[stack.length - 1] == tagName) { parseEndTag("", tagName); }