Skip to content

fix(imagekit): stop double-encoding hyphens in aspect ratio values - #199

Open
cpruijsen wants to merge 1 commit into
ascorbic:mainfrom
cpruijsen:fix/issue-195
Open

cpruijsen wants to merge 1 commit into
ascorbic:mainfrom
cpruijsen:fix/issue-195

Conversation

@cpruijsen

Copy link
Copy Markdown

Summary

generate now decodes formatter output before URLSearchParams.set, so the query string encodes once. The decoded tr is ar-9-16, matching ImageKit's documented form.

ImageKit ar values such as 9-16 were written as ar-9%252D16 in tr. After one query decode ImageKit sees ar-9%2D16, which is not a valid aspect ratio.

extract keeps hyphens that appear inside values, so official URLs like tr:ar-4-3,w-400 round-trip as ar: "4-3" instead of ar: "4", and transform() of a generated ar-9-16 URL no longer truncates the ratio.

Fixes #195.

Decision

Decode in ImageKit generate, and re-encode extra hyphens only in ImageKit extract. Alternative: change the shared operations parser to keep everything after the first key/value separator. That shared change made Uploadcare parse quality/lighter/ as "lighter/" (trailing / is their key/value separator). Can switch if you would rather fix the parser once for every provider.

Test plan

  • deno test src/providers/imagekit.test.ts
  • New tests fail without the source change and pass with it (generate is not %252D; extract of ar-9-16 / ar-4-3; transform keeps ar-9-16)
  • deno check src/
  • deno test src/ (85 tests)
  • Optional: request ?tr=w-640,ar-9-16 against a real ImageKit image and confirm the crop is 9:16

@changeset-bot

changeset-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 80ede73

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
unpic Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

ImageKit aspectRatio param double encoding

1 participant