Fix gradient dropping optional arguments set to 0 - #89
Merged
Conversation
`color`, `direction`, `start` and `stop` were validated and rendered based on truthiness, so an explicit `0` was silently dropped and imgproxy applied the default instead. For `stop: 0` this changed the resulting image: `gr:0.5` means `stop` is `1.0`, not `0`. Check for `undefined` instead, matching the `progressive_blur` option. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G8Aa3xeVUCaxKtQJDzZhMo
This was referenced Aug 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #88, which introduced
progressive_blurwith explicitundefinedchecks rather than the truthiness checksgradientuses. This bringsgradientin line — and it turns out to be a real bug fix, not just a style change.The bug
color,direction,startandstopwere guarded withif (value)and rendered withvalue || "", so any falsy value was treated as "not provided":{ opacity: 0.5, stop: 0 }gr:0.5— imgproxy applies the defaultstopof 1.0gr:0.5::::0{ opacity: 0.5, start: 0 }gr:0.5gr:0.5:::0{ opacity: 0.5, direction: 0 }gr:0.5gr:0.5::0The
stop: 0case is the damaging one: the caller asks for a gradient that stops immediately and gets one spanning the whole image instead.start: 0anddirection: 0happen to coincide with imgproxy's defaults, so those were harmless in effect but still dropped the caller's input.Falsy values were also skipping validation entirely —
start: nullfrom a vanilla-JS caller rendered as an empty argument instead of raising.The fix
if (value !== undefined)for validation,value ?? ""for rendering. Nothing else changes: omitted arguments still render empty and trailing:are still trimmed.Behavior change worth noting
{ opacity: 0.5, color: "" }now throwsgradient.color must be 3, 6 or 8 characters long (with alpha)instead of silently rendering an empty argument. An empty string was never a valid hex color, so this surfaces a caller bug rather than hiding it — but it is a new exception on input that previously "worked", hence the patch changeset.Verification
tsc --noEmitclean,eslint src testscleanvitest run→ 97 files / 1100 tests passing (5 new, coveringstop: 0,start: 0,direction: 0,start: nullandcolor: "")Out of scope
The same truthiness pattern appears in
resize,trim,size,watermark,watermarkSize,unsharpMaskingandpngOptions. I have not audited whether any of them drops a meaningful0the waygradientdid — worth a separate look.🤖 Generated with Claude Code
https://claude.ai/code/session_01G8Aa3xeVUCaxKtQJDzZhMo