fix(handlers): parse all three modulate args (brightness, saturation, hue)#312
Open
dev48v wants to merge 1 commit into
Open
fix(handlers): parse all three modulate args (brightness, saturation, hue)#312dev48v wants to merge 1 commit into
dev48v wants to merge 1 commit into
Conversation
… hue) `modulate` declared `args: [VArg]`, so `parseArgs` only extracted the first value (brightness) from the URL and `saturation`/`hue` were always `undefined`. A request like `modulate_2_1_1` therefore failed with "Expected number above zero for saturation but received undefined". Declare all three arg mappers (`[VArg, VArg, VArg]`), matching the sibling handlers, so every value is parsed and forwarded to sharp. Fixes unjs#301
📝 WalkthroughWalkthroughThe modulate handler's args declaration was changed from a single VArg to three VArg entries, aligning it with its apply function that consumes brightness, saturation, and hue. A corresponding test was added using applyHandler to verify correct parsing of delimited argument strings. ChangesModulate args fix
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
🔗 Linked issue
Fixes #301
📚 Description
The
modulatehandler declaredargs: [VArg], soparseArgsonly pulled the first value out of the URL segment. Itsapplytakes three (brightness, saturation, hue), sosaturationandhuewere alwaysundefined.A request like
/_ipx/modulate_2_1_1/example.pngthen failed with:Fix: declare all three arg mappers —
args: [VArg, VArg, VArg]— matching the sibling multi-arg handlers, so every value is parsed and forwarded to sharp. One-line change plus a regression test.Thanks to @wuiyang for pinpointing the exact location (
src/handlers/handlers.ts).✅ Test
Added a test that drives the handler through
applyHandler(i.e. throughparseArgs, notapply()directly) so it covers the arg-count contract:vitest run test/handlers/handlers.test.ts→ 53 passed (incl. the new test)eslint .→ cleanThe existing
modulate.apply() returns expected valuestest calledapply()with three args directly, so it didn't exercise the parsing gap; the new test does.Summary by CodeRabbit
Bug Fixes
Tests