Inconsistent line ending behavior in firefox in windows

We have a real bizarre problem when we make a message, line ending \r\n , but when we pull the value using javascript, it just gets \n . This causes problems because for our system, the creation will do the message of the usual form, and the update will pull the values ​​from the form to create the ajax request. Later we do a string comparison over a given field and see that this weird mix between \r exists or does not exist.

IE handles this tone (ALWAYS \r\n ), FF on windows will send using \r\n , and only \n will be reported in javascript. What is REALLY FREAKIN STRANGE, although this is on Linux, firefox, and chrome will be placed with \r\n , and when you execute document.getElementById('text-area-id').value will always be displayed only \n .

Is this some kind of dusty corner of the HTTP spec or something like that? Do browsers implement this so that Windows servers do not die? Is there a way around this and then sanitize each area? What I expect is both JS and HTTP POST to behave the same and use the default system on any system they are on.

+4
source share
1 answer

\r seems to be an illegal character in the DOM, so you won't see it with a script. Firefox converts linear platform extensions to \n when you set the textarea value. On the other hand, when submitting a form, she thinks she needs to use the HTTP linebreak standard, which is apparently \r\n . Therefore, it converts them all before submitting the form.

0
source

Source: https://habr.com/ru/post/1337053/


All Articles