From ae059387855f71567ad0bb8e24dbefb830b6c624 Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Sun, 6 Dec 2020 21:47:13 +0000 Subject: [PATCH] Fix catastrophic backtracking Former-commit-id: b6d4ec6664991164989bc4a809cf13c945adb006 [formerly add1f091841cf936e5e5a02ee7e8d99e9d0b6c57 [formerly 2f34f011c2b41a5501dcb6cfc8e3710ba1d21d80]] Former-commit-id: 28999c62eedfd9966726e4f34b97716e392cf32d Former-commit-id: b3202981b0ee58f9dc6b35252849e0d4fdb87c54 --- www/js/app.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index 1eb36aab..b8afb0bb 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -3078,23 +3078,25 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'cook /[^\\](\$\$?)((?:\\\$|(?!\1)[\s\S])+)\1/.test(htmlArticle) : false; //Replace all TeX SVGs with MathJax scripts if (params.useMathJax) { - htmlArticle = htmlArticle.replace(/]+?math-fallback-image)[^>]*?alt\s*=\s*(['"])((?:[^"']|(?!\1)[\s\S])+)[^>]+>/ig, - function (p0, p1, math) { - // Remove any rogue ampersands in MathJax due to double escaping (by Wikipedia) - math = math.replace(/&/g, '&'); - // Change any mbox commands to fbox (because KaTeX doesn't support mbox) - math = math.replace(/mbox{/g, 'fbox{'); - return ''; - }); // Deal with any newer MathML blocks htmlArticle = htmlArticle.replace(/(]+alttext=(["']))((?:[^"']|[\s\S](?!\2))+?)(\2(?:[^<]|<(?!\/math))+(?:[^<]|<(?!img))+)]+?class=["'][^"']*?mwe-math-fallback-image[^>]+>/ig, - function (_p0, p1, _p2, math, p4) { - // Remove any rogue ampersands in MathJax due to double escaping (by Wikipedia) - math = math.replace(/&/g, '&'); - // Change any mbox commands to fbox (because KaTeX doesn't support mbox) - math = math.replace(/mbox{/g, 'fbox{'); - return p1 + math + p4 + ''; - }); + function (_p0, p1, _p2, math, p4) { + // Remove any rogue ampersands in MathJax due to double escaping (by Wikipedia) + math = math.replace(/&/g, '&'); + // Change any mbox commands to fbox (because KaTeX doesn't support mbox) + math = math.replace(/mbox{/g, 'fbox{'); + return p1 + math + p4 + ''; + }); + // Older math blocks + htmlArticle = htmlArticle.replace(/]+?math-fallback-image)[^>]*?alt\s*=\s*(['"])((?:[^"']|(?!\1)[\s\S])+)[^>]+>/ig, + function (p0, p1, math) { + // Remove any rogue ampersands in MathJax due to double escaping (by Wikipedia) + math = math.replace(/&/g, '&'); + // Change any mbox commands to fbox (because KaTeX doesn't support mbox) + math = math.replace(/mbox{/g, 'fbox{'); + return ''; + }); + } params.containsMathTex = params.useMathJax ? /