When a string is appended to a FormData
object and sent to Laravel server, who decides the encoding that will be used? How can we make sure that the string length reported on the client-side matches the one that we get on the server, and not changed due to control characters, especially new line (rn
vs ‘n`)?
Detail
I’m POST
ing my model object that includes, among other things, its description that is a string (max: 1000 chars), using axios
from my SPA (Vue 3 + Vuetify + TS) to the backend Laravel server’s API endpoint. Validations are in place on both client and server sides. On that frontend, this description is being displayed in a v-textarea
that reports that the content is exactly 1000 characters, including 8 newline characters. This description, along with other data (including images), is then POST
ed to the server using a FormData
object.
On the server-side, this string is received as 1008 characters long instead of 1000, which causes the validation rule to fail. Upon inspecting the client- and server-side versions of the string, the only difference is that those newlines have been converted from n
to rn
at some point. I’m just looking for how to avoid this conversion or at least make the reported length match on both client and server sides.