How come a multipart form auto converts line feed characters into CRLF

22 Views Asked by At

When POSTing a Multipart form via Javascript as in the following example

var formdata = "A new string\nHere";
formdata.split('').map(function(x){return x.charCodeAt(0);}).join(',')

This will output showing that only the newline character has made it into the string as we'd expect

"65,32,110,101,119,32,115,116,114,105,110,103,10,72,101,114,101"

Now, lets take that data and place it into a Multipart form

var multipartForm = new FormData();
multipartForm.append('data', formdata);
multipartForm.get('data').indexOf('\r');
// 12

This shows that the \n character has been replaced with a \r\n set.

Why has this taken place?

This seems to show that the mutlipart form is being opinionated about the kind of data I am sending and changing it, which I'd rather it didn't (all arguments about \n vs \r\n aside).

0

There are 0 best solutions below