Skip to content

Fix prefixed gradients with uppercase keywords and units - #1566

Merged
ai merged 2 commits into
postcss:mainfrom
goranai:fix/gradient-uppercase
Nov 18, 2026
Merged

ai merged 2 commits into
postcss:mainfrom
goranai:fix/gradient-uppercase

Conversation

@goranai

@goranai goranai commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #1565

The gradient hack compared the function name, to, at and angle units case-sensitively. CSS treats them case-insensitively. So linear-gradient(TO RIGHT, red, blue) gave -webkit-gradient(linear, left top, left bottom, color-stop(RIGHT, TO), ...). 90DEG, 0.25TURN, 1Rad and 100GRAD were not converted for old WebKit. AT in radial gradients was not moved. LINEAR-GRADIENT(...) got no prefixes.

What changed in lib/hacks/gradient.js:

  • replace() matches the function name with toLowerCase().
  • A new lowerKeywords() lowercases to, at and a leading angle with a unit in the first argument, before the existing conversion runs.

Colors, stops and other words are not touched. The declaration the author wrote is never changed.

Behavior changes:

  • Uppercase or mixed-case gradient names now get prefixes. Before, they got none.
  • Prefixed copies of such gradients print the lowercase name and keywords, for example -webkit-linear-gradient(left, ...) for LINEAR-GRADIENT(to right, ...).
  • All-lowercase input gives the same output as before.

Known limits: calc() angles, comments inside the first argument and already prefixed input like -WEBKIT-LINEAR-GRADIENT( behave as before.

Tests: I added handles uppercase gradient keywords and units to test/autoprefixer.test.js. It fails on main. With the fix, npx uvu . '\.test\.js$' gives 274 passed, 0 failed, and oxlint reports no errors on my machine.

Validated with Claude Opus 5.5.

Comment thread lib/hacks/gradient.js Outdated
* Lowercase case-insensitive CSS keywords and angle units
* in the first gradient argument
*/
lowerKeywords(nodes) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move it to function, we do not need it as method

@goranai

goranai commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Done in b55a63a. lowerKeywords is now a plain function at the top of the file. All 274 tests pass.

@ai
ai merged commit 0f8eeca into postcss:main Nov 18, 2026
9 checks passed
@ai

ai commented Nov 18, 2026

Copy link
Copy Markdown
Member

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.

Uppercase TO, AT, angle units or gradient names break prefixed gradients

2 participants