Skip to content

fix: guard against undefined value in CSS variable resolution#604

Closed
ghost wants to merge 1 commit intomasterfrom
unknown repository
Closed

fix: guard against undefined value in CSS variable resolution#604
ghost wants to merge 1 commit intomasterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Mar 20, 2026

Summary

Fixes TypeError: Cannot read properties of undefined (reading 'indexOf') when resolveCSSVariables is enabled and a CSS property has an undefined value.

Root cause

replaceVariables() in lib/variables.js passes value to uniqueString() which calls string.indexOf(). When value is undefined (e.g., from malformed CSS), this crashes.

Fix

Add a type check at the start of replaceVariables() to return early for non-string values.

Tests

All 103 existing tests pass.

Fixes #582

When a CSS property has an undefined value, replaceVariables() crashes
with 'Cannot read properties of undefined (reading indexOf)' because
uniqueString() calls string.indexOf() on the undefined value.

Add a type check at the start of replaceVariables to return early
for non-string values.

Fixes #582
@ghost ghost closed this by deleting the head repository Mar 26, 2026
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

resolveCSSVariables: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'indexOf')

0 participants