Skip to content

fix: restore string modifier values in VArg#308

Open
benjamincanac wants to merge 1 commit into
unjs:mainfrom
benjamincanac:fix/varg-string-modifiers
Open

fix: restore string modifier values in VArg#308
benjamincanac wants to merge 1 commit into
unjs:mainfrom
benjamincanac:fix/varg-string-modifiers

Conversation

@benjamincanac
Copy link
Copy Markdown

@benjamincanac benjamincanac commented Jun 2, 2026

Summary

VArg returned undefined for any value that isn't valid JSON, since the modernize ts usage refactor swapped destr for a bare JSON.parse. This silently broke every string-valued modifier:

  • s_40x40 / s_200x200 (resize) → no resize applied
  • fit_cover, pos_top, kernel_nearest
  • hex background colors

JSON.parse("40x40") throws, so VArg returned undefined, and resize then computed [NaN] for the dimensions and bailed out.

Fix

Restore the destr-style fallback to the raw string when the value isn't valid JSON, while keeping "undefined" mapped to actual undefined (relied on by the existing test).

Test plan

  • pnpm test (54 passed, 9 skipped)
  • Manually verified /s_40x40/... now resizes

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of edge cases where arguments contain undefined values or non-JSON strings. The system now returns the original argument as a fallback when JSON parsing fails, ensuring more reliable argument processing.

`VArg` returned `undefined` for any value that isn't valid JSON, which
broke every string-valued modifier (`s_40x40`, `fit_cover`, `pos_top`,
`kernel_nearest`, hex backgrounds, etc.). The previous `destr`-based
implementation fell back to the raw string in this case. Restore that
fallback while keeping `"undefined"` mapped to `undefined`.
@benjamincanac benjamincanac requested a review from pi0 as a code owner June 2, 2026 14:34
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c2e46e76-8c05-4247-9032-b0f851b1b6e6

📥 Commits

Reviewing files that changed from the base of the PR and between 3189d0e and a4d2962.

📒 Files selected for processing (1)
  • src/handlers/utils.ts

📝 Walkthrough

Walkthrough

The PR modifies the VArg utility function in src/handlers/utils.ts to improve argument parsing: it now recognizes the string "undefined" and value undefined early and returns undefined immediately, and adds a fallback to return the original raw argument string after JSON parsing fails instead of ending with an undefined result.

Changes

VArg Argument Parsing Enhancement

Layer / File(s) Summary
VArg undefined and fallback handling
src/handlers/utils.ts
VArg adds early recognition of "undefined" strings and undefined values returning immediately, and a post-parse fallback returning the original raw argument string for non-JSON inputs.

Possibly related issues

Poem

🐰 A rabbit's helper sees the light,
When strings undefined need a sight,
No JSON maze shall lead astray—
Raw arguments find their way! ✨


🎯 2 (Simple) | ⏱️ ~5–10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main fix: restoring string modifier values in VArg after a refactor broke them.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

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.

1 participant