Skip to content
This repository was archived by the owner on Aug 1, 2024. It is now read-only.

Commit 0726fde

Browse files
Closure Teamcopybara-github
authored andcommitted
Add '#' to SafeStyle list of allowed characters inside functions. The fix enables to use the HEX color format in functions like linear-gradient().
https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient() RELNOTES: Add '#' to SafeStyle list of allowed characters inside functions. PiperOrigin-RevId: 402361256 Change-Id: Ib3144a91f94509015ddee246ea41d8bc265c721e
1 parent cfb2e44 commit 0726fde

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

closure/goog/html/safestyle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ const ALLOWED_FUNCTIONS = [
544544
*/
545545
const FUNCTIONS_RE = new RegExp(
546546
'\\b(' + ALLOWED_FUNCTIONS.join('|') + ')' +
547-
'\\([-+*/0-9a-z.%\\[\\], ]+\\)',
547+
'\\([-+*/0-9a-z.%#\\[\\], ]+\\)',
548548
'g');
549549

550550

closure/goog/html/safestyle_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ testSuite({
185185
{'color': 'var(--xyz, black)'});
186186
},
187187

188+
testCreate_allowsLinearGradient() {
189+
assertCreateEquals(
190+
'background:linear-gradient(red, blue);',
191+
{'background': 'linear-gradient(red, blue)'});
192+
assertCreateEquals(
193+
'background:linear-gradient(rgb(10,0,0), rgb(0,0,30));',
194+
{'background': 'linear-gradient(rgb(10,0,0), rgb(0,0,30))'});
195+
assertCreateEquals(
196+
'background:linear-gradient(#333, #eee);',
197+
{'background': 'linear-gradient(#333, #eee)'});
198+
},
199+
188200
testCreate_allowsSafeUrl() {
189201
assertCreateEquals('background:url("http://example.com");', {
190202
'background': SafeUrl.fromConstant(Const.from('http://example.com')),

0 commit comments

Comments
 (0)