Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix normalizing subtraction followed by a variable #10074

Merged

Conversation

sibbng
Copy link
Contributor

@sibbng sibbng commented Dec 14, 2022

Fixes #9832

-/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g
+/(-?\d*\.?\d(?!\b-\d.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g
                   ^ added `\d` to regex

This is fixed the issue but caused some false positives on classes like calc(var(--headings-h1-size)*100):

// normalize-data-types.test.js
-calc(var(--headings-h1-size)*100)
+calc(var(--headings-h1 - size) * 100)

I couldn't figure out how to fix that with regex. To solve this problem, I extracted the variable names and replaced them with safe ones before processing.

@thecrypticace thecrypticace self-assigned this Dec 14, 2022
@thecrypticace thecrypticace merged commit ce7ac96 into tailwindlabs:master Dec 14, 2022
@thecrypticace
Copy link
Contributor

Hah, clever fix! I spent some time trying to fix the regex but couldn't come up with one. Thanks!

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.

Subtraction in calc() arbitrary values not always normalized properly
2 participants