Skip to content

Commit

Permalink
Improve trusted-set-attr scriptlet
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Nov 16, 2024
1 parent 947602d commit c8174d6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions assets/resources/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { safeSelf } from './safe-self.js';
/******************************************************************************/

export function setAttrFn(
trusted = false,
logPrefix,
selector = '',
attr = '',
Expand All @@ -38,7 +39,7 @@ export function setAttrFn(
if ( attr === '' ) { return; }

const safe = safeSelf();
const copyFrom = /^\[.+\]$/.test(value)
const copyFrom = trusted === false && /^\[.+\]$/.test(value)
? value.slice(1, -1)
: '';

Expand Down Expand Up @@ -148,7 +149,7 @@ export function setAttr(
}
}

setAttrFn(logPrefix, selector, attr, value);
setAttrFn(false, logPrefix, selector, attr, value);
}
registerScriptlet(setAttr, {
name: 'set-attr.js',
Expand Down Expand Up @@ -187,7 +188,7 @@ export function trustedSetAttr(
) {
const safe = safeSelf();
const logPrefix = safe.makeLogPrefix('trusted-set-attr', selector, attr, value);
setAttrFn(logPrefix, selector, attr, value);
setAttrFn(true, logPrefix, selector, attr, value);
}
registerScriptlet(trustedSetAttr, {
name: 'trusted-set-attr.js',
Expand Down

0 comments on commit c8174d6

Please sign in to comment.