Skip to content

Commit 3046b9e

Browse files
committed
fix(cloudflare): handle URL encoding for src with query parameters
1 parent eefd617 commit 3046b9e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

.changeset/kind-flowers-sit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"unpic": patch
3+
---
4+
5+
fix(cloudflare): handle URL encoding for src with query parameters correctly

src/providers/cloudflare.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,15 @@ export const generate: URLGenerator<"cloudflare"> = (
114114
) => {
115115
const modifiers = operationsGenerator(operations);
116116
const url = toUrl(options?.domain ? `https://${options.domain}` : "/");
117-
url.pathname = `/cdn-cgi/image/${modifiers}/${
118-
stripLeadingSlash(src.toString())
119-
}`;
117+
118+
const srcStr = src.toString();
119+
let pathSuffix = stripLeadingSlash(srcStr);
120+
121+
if (srcStr.startsWith("http") && srcStr.includes("?")) {
122+
pathSuffix = encodeURIComponent(srcStr);
123+
}
124+
125+
url.pathname = `/cdn-cgi/image/${modifiers}/${pathSuffix}`;
120126
return toCanonicalUrlString(url);
121127
};
122128

0 commit comments

Comments
 (0)