Skip to content

fix(handlers): parse all three modulate args (brightness, saturation, hue)#312

Open
dev48v wants to merge 1 commit into
unjs:mainfrom
dev48v:fix/modulate-args
Open

fix(handlers): parse all three modulate args (brightness, saturation, hue)#312
dev48v wants to merge 1 commit into
unjs:mainfrom
dev48v:fix/modulate-args

Conversation

@dev48v

@dev48v dev48v commented Jul 8, 2026

Copy link
Copy Markdown

🔗 Linked issue

Fixes #301

📚 Description

The modulate handler declared args: [VArg], so parseArgs only pulled the first value out of the URL segment. Its apply takes three (brightness, saturation, hue), so saturation and hue were always undefined.

A request like /_ipx/modulate_2_1_1/example.png then failed with:

[IPX_ERROR] Expected number above zero for saturation but received undefined of type undefined

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. through parseArgs, not apply() directly) so it covers the arg-count contract:

modulate parses all three args (brightness, saturation, hue) (#301)
  • vitest run test/handlers/handlers.test.ts → 53 passed (incl. the new test)
  • eslint . → clean

The existing modulate.apply() returns expected values test called apply() with three args directly, so it didn't exercise the parsing gap; the new test does.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed the image modulation command so it now correctly accepts brightness, saturation, and hue values together.
    • Improved handling of modulation inputs so the applied settings match the values provided.
  • Tests

    • Added coverage for modulation input parsing and verified the expected image adjustment values are passed through.

… 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
@dev48v dev48v requested a review from pi0 as a code owner July 8, 2026 22:12
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Modulate args fix

Layer / File(s) Summary
Handler args contract and test
src/handlers/handlers.ts, test/handlers/handlers.test.ts
modulate's Handler declaration now expects three VArg entries instead of one, matching its apply function; a new test uses applyHandler to confirm "2_1_1" parses into { brightness: 2, saturation: 1, hue: 1 }.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address issue #301 by parsing and forwarding all three modulate args and adding regression coverage.
Out of Scope Changes check ✅ Passed The diff stays focused on the modulate argument parsing fix and its test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing modulate to parse all three arguments.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Mismatch modulate args count

1 participant