From bb8728105719efe3c1f11d8a6996ea18597dbb6c Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 15 Sep 2021 13:21:34 +1200 Subject: [PATCH] Apply changes to `markdownLegacy.js` --- shared/naturalcrit/markdownLegacy.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/shared/naturalcrit/markdownLegacy.js b/shared/naturalcrit/markdownLegacy.js index 27cf10e9c..b42302fb8 100644 --- a/shared/naturalcrit/markdownLegacy.js +++ b/shared/naturalcrit/markdownLegacy.js @@ -99,9 +99,15 @@ const sanatizeScriptTags = (content)=>{ const tagTypes = ['div', 'span', 'a']; const tagRegex = new RegExp(`(${ _.map(tagTypes, (type)=>{ - return `\\<${type}|\\`; + return `\\<${type}\\b|\\`; }).join('|')})`, 'g'); +// Special "void" tags that can be self-closed but don't need to be. +const voidTags = new Set([ + 'area', 'base', 'br', 'col', 'command', 'hr', 'img', + 'input', 'keygen', 'link', 'meta', 'param', 'source' +]); + module.exports = { marked : Markdown, @@ -128,6 +134,13 @@ module.exports = { }); } if(match === ``){ + // Closing tag: Check we expect it to be closed. + // The accumulator may contain a sequence of voidable opening tags, + // over which we skip before checking validity of the close. + while (acc.length && voidTags.has(_.last(acc).type) && _.last(acc).type != type) { + acc.pop(); + } + // Now check that what remains in the accumulator is valid. if(!acc.length){ errors.push({ line : lineNumber,