Skip to content

getComputedStyle(element) fails to correctly parse var() inside other css functions #1837

@fimion

Description

@fimion

Describe the bug
The current implementation of regexing for variables inside of CSSStyleDeclarationComputedStyle does not correctly work when a variable definition is inside a non var() call (eg background-color: rgb(0 128 0/var(--bg-color-alpha, 1)); computes down to rgb(231 253 251/1 and leaves out the closing parenthesis)

This is in part because the last part of this regex: /var\( *(--[^), ]+)\)|var\( *(--[^), ]+), *(.+)\)/ is too greedy using a .+ selector.

The resulting behavior is that the css property definition is invalid and is thrown out.

To Reproduce
Steps to reproduce the behavior:
#1838 reproduces the issue in tests

Expected behavior
The correct behavior was happening prior to 1493fa6cd082cb743f98ead8574dd9dbc3eae5b6.

Screenshots
If applicable, add screenshots to help explain your problem.

Device:

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context

(I have been working on updating some dependencies, and noticed this bug, so I've spent this morning hunting down the issue and was able to pinpoint it to a specific version where it started breaking)

I don't know if reverting to the previous behavior is a good idea, or if it would be better to try and make a more complicated regex.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions