Improve `trusted-set-attr` scriptlet

Related feedback:
11ca4a3923 (commitcomment-149148167)
This commit is contained in:
Raymond Hill 2024-11-16 08:10:25 -05:00
parent 947602d4fe
commit c8174d6032
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 4 additions and 3 deletions

View File

@ -29,6 +29,7 @@ import { safeSelf } from './safe-self.js';
/******************************************************************************/ /******************************************************************************/
export function setAttrFn( export function setAttrFn(
trusted = false,
logPrefix, logPrefix,
selector = '', selector = '',
attr = '', attr = '',
@ -38,7 +39,7 @@ export function setAttrFn(
if ( attr === '' ) { return; } if ( attr === '' ) { return; }
const safe = safeSelf(); const safe = safeSelf();
const copyFrom = /^\[.+\]$/.test(value) const copyFrom = trusted === false && /^\[.+\]$/.test(value)
? value.slice(1, -1) ? value.slice(1, -1)
: ''; : '';
@ -148,7 +149,7 @@ export function setAttr(
} }
} }
setAttrFn(logPrefix, selector, attr, value); setAttrFn(false, logPrefix, selector, attr, value);
} }
registerScriptlet(setAttr, { registerScriptlet(setAttr, {
name: 'set-attr.js', name: 'set-attr.js',
@ -187,7 +188,7 @@ export function trustedSetAttr(
) { ) {
const safe = safeSelf(); const safe = safeSelf();
const logPrefix = safe.makeLogPrefix('trusted-set-attr', selector, attr, value); const logPrefix = safe.makeLogPrefix('trusted-set-attr', selector, attr, value);
setAttrFn(logPrefix, selector, attr, value); setAttrFn(true, logPrefix, selector, attr, value);
} }
registerScriptlet(trustedSetAttr, { registerScriptlet(trustedSetAttr, {
name: 'trusted-set-attr.js', name: 'trusted-set-attr.js',