microsoft / microsoft/vscode

CSS: var() fallbacks that contain commas are truncated to invalid CSS

Open
#332,613 0 comments 0 reactions 1 assignee Claimed by @hawkticehurst View on GitHub
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

### Bug description

`asCssValueWithDefault` in `src/vs/base/browser/cssValue.ts` truncates a `var(...)` fallback at its second comma:

```
asCssValueWithDefault('var(--x, rgba(0, 0, 0, 0.5))', 'white')
```

produces `var(--x, rgba(0)` - an unbalanced fragment that the CSS parser silently drops, so the whole declaration is lost instead of falling back.

Commas inside functions are part of the fallback per the css-variables spec; only the first top level comma separates variable name from fallback.

### Steps to reproduce

1. Call `asCssValueWithDefault('var(--x, rgba(0, 0, 0, 0.5))', 'white')`.
2. Observe the returned string is truncated at the second comma of the rgba() call.

### Expected behavior

The full fallback is preserved: `var(--x, rgba(0, 0, 0, 0.5))`.

### Version tested

Reproduced against compiled output on `main` (commit `38ec3d57f91b`). A fix is ready that splits at the first comma only and keeps everything after it as the fallback, with regression tests.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.