fix: trim url for cloudflare worker (#2830)

Fixes
https://discord.com/channels/955905230107738152/1199803387005390858/1199803387005390858

Here fixed the issue with leading spaces in resource urls fail when
fetch in workers. Trimmed urls and added validation for urls.
This commit is contained in:
Bogdan Chadkin authored and GitHub committed 2024-01-26 20:12:32 +07:00
1 parent 2816784602
commit 4ef839aba7
2 files changed
+8 -1

No files matched your search

@@ -309,6 +309,11 @@ export const ResourceForm = forwardRef<
if (evaluatedValue.length === 0) {
return "URL is required";
}
try {
new URL(evaluatedValue);
} catch {
return "URL is invalid";
}
},
});
const [method, setMethod] = useState<Resource["method"]>(
+3 -1
View File
@@ -13,7 +13,9 @@ export const loadResource = async (resourceData: Resource) => {
requestInit.body = body;
}
try {
const response = await fetch(url, requestInit);
// cloudflare workers fail when fetching url contains spaces
// even though new URL suppose to trim them on parsing by spec
const response = await fetch(url.trim(), requestInit);
let data;
if (
response.ok &&