fix(cropping): respect explicit height parameter with limit crop mode#244
Open
error9098x wants to merge 1 commit intocloudinary-community:mainfrom
Open
fix(cropping): respect explicit height parameter with limit crop mode#244error9098x wants to merge 1 commit intocloudinary-community:mainfrom
error9098x wants to merge 1 commit intocloudinary-community:mainfrom
Conversation
…t height Fixes cloudinary-community#231 - url-loader was ignoring height option when crop mode is 'limit'. The issue was caused by explicitly excluding the 'limit' crop mode from height parameter inclusion. This prevented height from being included even when both width and height were explicitly provided by the user. Updated the logic to: - Include height when explicitly provided (unless using aspect ratio) - Exclude height only when aspect ratio is used (as it determines height automatically) - Apply to all crop modes, including 'limit' This allows Cloudinary's limit transformation to respect both width and height constraints as documented in their API. BREAKING CHANGE: URLs generated with width and height will now include both parameters for limit crop mode. Update any existing code that depends on the previous behavior of omitting height with limit crop. Test coverage: - Updated 12 test cases to expect h_ parameter with c_limit - All 146 tests passing - No lint errors
Author
|
@eportis-cloudinary Would appreciate your feedback on this approach to fixing #231! |
Contributor
|
Hi @error9098x ! Thank you for this thurough analysis and PR. On first glance I really like the approach, and this would be a breaking change that we are not going to be able to merge into the current major version. I am currently cleaning up Hacktoberfest issues and because this affects such a common, fundamental case will not be able to give this the consideration it needs over the next couple of weeks. I hope to give it a thorough review in early December. I will be in touch then. Again: thank you! |
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.
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: