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.
I noticed some odd behavior when using prefixes, so I threw this together. Happy to discuss. Thanks!
Summary
CloudinaryStorageAdapter: Normalize paths, prevent double prefixing, and infer resource type for getUrl/write
This PR improves
CloudinaryStorageAdapterpath handling and resource-type detection to produce correct public IDs and URLs across platforms, while avoiding double application of the configured prefix. It also adds comprehensive unit tests to guard against regressions.Key Changes
public_idusingdirname/filenamewith forward slashes only, ensuring nested directories are preserved../or/when applying a prefix to avoidprefix/./fileorprefix//fileartifacts.resource_typevia:image/*→imagevideo/*→videorawgetUrlnow resolves the correctpublic_idand inferredresource_typebefore querying Admin API, ensuring the returned secure URL matches the resource.applyPrefixToPathnow short-circuits if the incoming path already begins with the configured prefix, preventing duplication in list/delete directory operations.str_starts_withand a smallmatch(true)to improve clarity.Files Changed
src/CloudinaryStorageAdapter.phpprepareResourceto normalize paths, construct IDs consistently, apply prefix safely, and inferresource_typefrom MIME type.applyPrefixToPathagainst double prefixing.tests/Unit/CloudinaryStorageAdapterTest.phppublic_idandimageresource type.videoresource type.rawresource type../and/stripping.getUrlbehavior for images and videos.getUrlwith prefixed adapter:Why
public_idgeneration on Windows-like inputs (backslashes), preventing broken uploads/URL lookups.Fixtures/Fixtures/...orFixtures//...issues when users pass already-prefixed paths or paths with leading separators.resource_typeis used for Admin/Upload API calls, avoiding 400s due to mismatched types.Behavior Examples
dir\nested\picture.jpgpublic_idwith backslashes and wrongresource_type.public_id=dir/nested/picture,resource_type=image.Fixtures:/file.jpgor./file.jpgpublic_id=Fixtures/file, no double prefixing.getUrl('media/clip.mp4')asset('media/clip', ['resource_type' => 'video'])and returnssecure_url.Tests
Backwards Compatibility
public_idandresource_typedetection.str_starts_with(PHP 8.0+).Risks
str_starts_with($trimmed, $this->prefix)assumes exact textual prefix; if users intentionally pass different-cased prefixes, behavior will not double-apply but may differ on case-sensitive expectations.Rollout/Verification
Checklist
getUrl,listContents,delete*resource_typeinference for image/video/raw