From ade0e572d29c0d306e53e064b4b1cd0158ee3f3c Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Tue, 3 Oct 2023 08:27:22 +0200 Subject: [PATCH] parser: factor out getting lower-case canonical tag name Signed-off-by: Thomas Lamprecht --- src/Parser.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Parser.js b/src/Parser.js index 2d126da..60eff5d 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -24,6 +24,7 @@ Ext.define('Proxmox.Markdown', { for (let i=node.attributes.length; i--;) { const name = node.attributes[i].name; const value = node.attributes[i].value; + const canonicalTagName = node.tagName.toLowerCase(); // TODO: we may want to also disallow class and id attrs if ( !/^(class|id|name|href|src|alt|align|valign|disabled|checked|start|type|target)$/i.test(name) @@ -34,8 +35,8 @@ Ext.define('Proxmox.Markdown', { let url = new URL(value, window.location.origin); if ( _isHTTPLike(url.protocol) || - node.tagName.toLowerCase() === 'a' || - (node.tagName.toLowerCase() === 'img' && url.protocol.toLowerCase() === 'data:') + canonicalTagName === 'a' || + (canonicalTagName === 'img' && url.protocol.toLowerCase() === 'data:') ) { node.attributes[i].value = url.href; } else { @@ -44,7 +45,7 @@ Ext.define('Proxmox.Markdown', { } catch (e) { node.attributes.removeNamedItem(name); } - } else if (name === 'target' && node.tagName.toLowerCase() !== 'a') { + } else if (name === 'target' && canonicalTagName !== 'a') { node.attributes.removeNamedItem(name); } }