fix(cropping): respect explicit height parameter with limit crop mode #244
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.
Description
This PR fixes a critical bug in the url-loader's cropping plugin where the height parameter was being ignored when using the
limitcrop mode, even when both width and height were explicitly provided.The Problem
When users provided both
widthandheightwith the defaultlimitcrop mode:Expected:
c_limit,w_800,h_600Actual (Bug):
c_limit,w_800❌This meant the height constraint was never applied, only width was enforced.
The Solution
Updated the height inclusion logic from checking if crop is
"limit"to checking if an aspect ratio is being used:"limit"Flow Diagram
flowchart TD A["User provides width & height"] --> B{"Is aspect ratio used?"} B -- Yes --> C["Exclude height<br>(AR determines height)"] B -- No --> D["Include height<br>(h_ parameter added)"] C --> E["Generated URL:<br>c_MODE,w_X,ar_Y"] D --> F["Generated URL:<br>c_MODE,w_X,h_Y"] style C fill:#e1f5ff,color:#000000 style D fill:#c8e6c9,color:#000000 style E fill:#e1f5ff,color:#000000 style F fill:#c8e6c9,color:#000000Issue Ticket Number
Fixes #231
Type of change
Changes Made
1. Core Bug Fix
File:
packages/url-loader/src/plugins/cropping.ts(Lines 224-229)2. Test Updates
File:
packages/url-loader/tests/lib/cloudinary.spec.tsUpdated 12 test cases to expect the height parameter in URLs when both width and height are provided:
c_limit,w_100,h_100✓c_limit,w_100,h_100✓c_limit,w_100,h_100✓c_limit,w_100,h_100✓Test Results
✅ All Tests Passing
Specific Test File Results
cloudinary.spec.tscropping.spec.tsfill-background.spec.tsoverlays.spec.tsremove.spec.tsBuild & Lint Verification
graph LR A["Build"] -->|✅ Success| B["Type Check"] B -->|✅ Clean| C["Lint"] C -->|✅ No Errors| D["Tests"] D -->|✅ All Pass| E["Ready to Merge"] style A fill:#c8e6c9,color:#000000 style B fill:#c8e6c9,color:#000000 style C fill:#c8e6c9,color:#000000 style D fill:#c8e6c9,color:#000000 style E fill:#c8e6c9,color:#000000Before & After Comparison
Before (Bug)
After (Fixed)
Other Crop Modes (Unchanged, Correct Behavior)
Impact Analysis
Breaking Change Notice
Version Impact: 6.3.0 (or 6.2.1 depending on release strategy)
URLs generated with width AND height will now include both parameters:
Migration Required: Any code relying on the old behavior of omitting height should be reviewed.
Affected Users
Users who:
widthandheightwithlimitcrop (now works correctly)Root Cause Analysis
flowchart TD A["Bug Report #231"] --> B["User provided width & height"] B --> C@{ label: "Default crop mode: 'limit'" } C --> D["Height parameter missing in URL"] E["Root Cause Analysis"] --> F["Line 227 in cropping.ts"] F --> G@{ label: "Logic: exclude height if crop IS 'limit'" } G --> H["❌ Wrong assumption:<br>ALL crop modes should accept height"] I["Fix Applied"] --> J["Changed logic:<br>exclude only when aspect ratio used"] J --> K@{ label: "✅ Now correct:<br>height included for 'limit'" } C@{ shape: rect} G@{ shape: rect} K@{ shape: rect} style A fill:#ffcdd2,color:#000000 style D fill:#ffcdd2,stroke:none,color:#000000 style H fill:#ffcdd2,stroke:none,color:#000000 style K fill:#c8e6c9,color:#000000,stroke:noneCode Review Checklist
Checklist
Additional Context
GitHub Issue Reference
Issue #231: url-loader ignores height option when crop mode is "limit"
Commit Information
Documentation Updates Needed
Dependencies
No new dependencies added - this is a logic fix only.
Package Versions Used: