Skip to content

Fix: URL encode transform parameters to handle special characters#4

Open
richardfrankza wants to merge 1 commit intolenvanessen:masterfrom
richardfrankza:fix/url-encode-transform-params
Open

Fix: URL encode transform parameters to handle special characters#4
richardfrankza wants to merge 1 commit intolenvanessen:masterfrom
richardfrankza:fix/url-encode-transform-params

Conversation

@richardfrankza
Copy link
Copy Markdown

Problem

Special characters in transform parameters (like # in background colors) are not being URL-encoded, which causes HTML attribute parsing issues.

For example, background=#FFFFFF in the generated URL breaks the srcset attribute because the # character is not properly escaped.

Solution

Added rawurlencode() when building the transform directive URL parameters. This ensures special characters are properly encoded:

  • #FFFFFF becomes %23FFFFFF
  • Other special characters like ,, =, etc. are also properly handled

Example

Before:

srcset="https://example.com/cdn-cgi/image/width=300,background=#FFFFFF/image.jpg"

After:

srcset="https://example.com/cdn-cgi/image/width=300,background=%23FFFFFF/image.jpg"

Testing

Tested with letterbox mode using a white background (#FFFFFF) and confirmed the URLs are now properly encoded in the rendered HTML attributes.

Special characters in transform parameters (like # in background colors)
need to be URL-encoded to avoid HTML attribute parsing issues.

For example, background=#FFFFFF now becomes background=%23FFFFFF

This ensures the srcset attribute is properly formatted when rendered in HTML.
@richardfrankza richardfrankza marked this pull request as ready for review October 12, 2025 15:46
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.

1 participant