For Workes & Pages, what is the name of the domain?
playground
What is the issue or error you’re encountering
When FormData is posted to a worker, new lines are converted to carriage return + new line.
What are the steps to reproduce the issue?
Here is a playground link which reproduces the issue.
// FormData: new line is received on the server as carriage return + new line
const html = `
<script type="module">
const body = new FormData();
body.set('content', String.fromCharCode(10));
const response = await fetch(location.origin, { method: 'POST', body });
document.body.textContent = await response.text();
</script>`
export default {
async fetch(request) {
if (request.method === 'GET') {
return new Response(html, { headers: { 'content-type': 'text/html' } });
};
if (request.method === 'POST') {
const body = await request.formData();
const content = body.get('content');
const message =`Received length: ${content.length}; Received chars: ${Array.from(content).map(c => c.charCodeAt(0)).join(',')}`;
return new Response(message, { headers: { 'content-type': 'text/plain' } });
}
}
};