From c8174d60320cedb8a22afedae2a3acddac9c8bf1 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 16 Nov 2024 08:10:25 -0500 Subject: [PATCH] Improve `trusted-set-attr` scriptlet Related feedback: https://github.com/gorhill/uBlock/commit/11ca4a39239478e35605ec072fca140ac4c70d3b#commitcomment-149148167 --- assets/resources/attribute.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/assets/resources/attribute.js b/assets/resources/attribute.js index 0c50daf87..7873183de 100644 --- a/assets/resources/attribute.js +++ b/assets/resources/attribute.js @@ -29,6 +29,7 @@ import { safeSelf } from './safe-self.js'; /******************************************************************************/ export function setAttrFn( + trusted = false, logPrefix, selector = '', attr = '', @@ -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) : ''; @@ -148,7 +149,7 @@ export function setAttr( } } - setAttrFn(logPrefix, selector, attr, value); + setAttrFn(false, logPrefix, selector, attr, value); } registerScriptlet(setAttr, { name: 'set-attr.js', @@ -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',