Skip to content

Cloudflare Images URL transformation broken when variant already present #188

@ascorbic

Description

@ascorbic

Problem

When a Cloudflare Images URL already has a variant/transforms in the path, Unpic generates malformed srcset URLs.

Input URL

https://imagedelivery.net/5LGXGUnHU18h6ehN_xjpXQ/abc123/public

or with transforms:

https://imagedelivery.net/5LGXGUnHU18h6ehN_xjpXQ/abc123/w=1200,fit=scale-down

Output (broken)

https://imagedelivery.net/5LGXGUnHU18h6ehN_xjpXQ/abc123/public=undefined,w=640,h=480,fit=cover 640w

The =undefined is clearly wrong, and it's appending to the existing variant instead of replacing it.

Expected

Either:

  1. Replace the existing variant with the new transforms
  2. Or detect that transforms are already present and skip transformation

Working case

When the URL has no variant, it works correctly:

// Input
https://imagedelivery.net/5LGXGUnHU18h6ehN_xjpXQ/abc123

// Output (correct)
https://imagedelivery.net/5LGXGUnHU18h6ehN_xjpXQ/abc123/w=640,h=480,fit=cover 640w

Workaround

We're currently stripping the variant from URLs before passing to Unpic and using the base URL only.

Version

@unpic/core 1.0.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions