@fluentui/web-components 3.1.1 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14404,13 +14404,24 @@ function setTheme(theme, node = document) {
14404
14404
  setLocalTheme(theme, node);
14405
14405
  }
14406
14406
  }
14407
+ const TOKEN_NAME_REGEX = /^[a-zA-Z_-][a-zA-Z0-9_-]*$/;
14408
+ function sanitizeTokenName(name) {
14409
+ return TOKEN_NAME_REGEX.test(name) ? name : "";
14410
+ }
14411
+ const TOKEN_VALUE_BLOCK_REGEX = /(;|{|}|\/\*|\*\/|@import|url\s*\(|expression\s*\(|javascript:)/i;
14412
+ function sanitizeTokenValue(value) {
14413
+ return TOKEN_VALUE_BLOCK_REGEX.test(value) ? "" : value;
14414
+ }
14407
14415
  function getThemeStyleText(theme) {
14408
14416
  if (!themeStyleTextMap.has(theme)) {
14409
- const tokenDeclarations = [];
14410
- for (const [tokenName, tokenValue] of Object.entries(theme)) {
14411
- tokenDeclarations.push(`--${tokenName}:${tokenValue.toString()};`);
14412
- }
14413
- themeStyleTextMap.set(theme, tokenDeclarations.join(""));
14417
+ themeStyleTextMap.set(
14418
+ theme,
14419
+ Object.keys(theme).reduce((acc, token) => {
14420
+ const tokenName = sanitizeTokenName(token);
14421
+ const tokenValue = sanitizeTokenValue(theme[token].toString());
14422
+ return tokenName && tokenValue ? `${acc}--${tokenName}:${tokenValue};` : acc;
14423
+ }, "")
14424
+ );
14414
14425
  }
14415
14426
  return themeStyleTextMap.get(theme);
14416
14427
  }