parser: factor out getting lower-case canonical tag name

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2023-10-03 08:27:22 +02:00
parent b4b3bcad18
commit ade0e572d2

View File

@ -24,6 +24,7 @@ Ext.define('Proxmox.Markdown', {
for (let i=node.attributes.length; i--;) { for (let i=node.attributes.length; i--;) {
const name = node.attributes[i].name; const name = node.attributes[i].name;
const value = node.attributes[i].value; const value = node.attributes[i].value;
const canonicalTagName = node.tagName.toLowerCase();
// TODO: we may want to also disallow class and id attrs // TODO: we may want to also disallow class and id attrs
if ( if (
!/^(class|id|name|href|src|alt|align|valign|disabled|checked|start|type|target)$/i.test(name) !/^(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); let url = new URL(value, window.location.origin);
if ( if (
_isHTTPLike(url.protocol) || _isHTTPLike(url.protocol) ||
node.tagName.toLowerCase() === 'a' || canonicalTagName === 'a' ||
(node.tagName.toLowerCase() === 'img' && url.protocol.toLowerCase() === 'data:') (canonicalTagName === 'img' && url.protocol.toLowerCase() === 'data:')
) { ) {
node.attributes[i].value = url.href; node.attributes[i].value = url.href;
} else { } else {
@ -44,7 +45,7 @@ Ext.define('Proxmox.Markdown', {
} catch (e) { } catch (e) {
node.attributes.removeNamedItem(name); node.attributes.removeNamedItem(name);
} }
} else if (name === 'target' && node.tagName.toLowerCase() !== 'a') { } else if (name === 'target' && canonicalTagName !== 'a') {
node.attributes.removeNamedItem(name); node.attributes.removeNamedItem(name);
} }
} }