diff --git a/packages/happy-dom/src/css/declaration/element-style/CSSStyleDeclarationElementStyle.ts b/packages/happy-dom/src/css/declaration/element-style/CSSStyleDeclarationElementStyle.ts index bdbf0a6dc..b3152020a 100644 --- a/packages/happy-dom/src/css/declaration/element-style/CSSStyleDeclarationElementStyle.ts +++ b/packages/happy-dom/src/css/declaration/element-style/CSSStyleDeclarationElementStyle.ts @@ -19,7 +19,7 @@ import CSSMeasurementConverter from '../measurement-converter/CSSMeasurementConv import MediaQueryList from '../../../match-media/MediaQueryList.js'; import WindowBrowserSettingsReader from '../../../window/WindowBrowserSettingsReader.js'; -const CSS_VARIABLE_REGEXP = /var\( *(--[^), ]+)\)|var\( *(--[^), ]+), *([^), ]+)\)/g; +const CSS_VARIABLE_REGEXP = /var\( *(--[^), ]+)\)|var\( *(--[^), ]+), *([^), ]+)\)/; const CSS_MEASUREMENT_REGEXP = /[0-9.]+(px|rem|em|vw|vh|%|vmin|vmax|cm|mm|in|pt|pc|Q)/g; type IStyleAndElement = { @@ -364,11 +364,10 @@ export default class CSSStyleDeclarationElementStyle { * @returns CSS value. */ private parseCSSVariablesInValue(value: string, cssVariables: { [k: string]: string }): string { - const regexp = new RegExp(CSS_VARIABLE_REGEXP); let newValue = value; let match; - while ((match = regexp.exec(newValue)) !== null) { + while ((match = newValue.match(CSS_VARIABLE_REGEXP)) !== null) { // Fallback value - E.g. var(--my-var, #FFFFFF) if (match[2] !== undefined) { newValue = newValue.replace(match[0], cssVariables[match[2]] || match[3]);