The result of JS encodingURIComponent is different from the result generated by FORM

I thought that the values ​​entered into the forms are correctly encoded by browsers.

But this simple test file test_get_vs_encodeuri.html shows that it is not:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
   <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
   <title></title>
</head><body>

<form id="test" action="test_get_vs_encodeuri.html" method="GET" onsubmit="alert(encodeURIComponent(this.one.value));">
   <input name="one" type="text" value="Euro-€">
   <input type="submit" value="SUBMIT">
</form>

</body></html>

When you click the submit button:

encodeURICompenent encodes the input value to "Euro-% E2% 82% AC"

, while the browser only writes a simple “Euro-% 80” to the GET request

  • Can someone explain?

  • How do I encode everything in the same way as FORM (windows-1252) using Javascript ??? (escape function doesn't work, encodeURIComponent doesn't work either)?

Or does encodeURIComponent do unnecessary conversions?

0
2

. charset Windows-1252, 128, Windows-1252 0x80. encodeURICompenent , UTF-8, , Unicodes, 8364 (PDF), UTF-8 0xE282AC.

UTF-8 . UTF-8 Windows-1252.

+5

, - . , :

Content encoding issue
(: boogdesign.com)

€ , encodeURIComponent. , - , encodeURIComponent. , GET. , URL-, :

test-get-vs-encodeuri.html?one=Euro-%80

UTF-8, URL-, ( Firefox):

http://www.boogdesign.com/examples/encode/test-get-vs-encodeuri-utf8.html?one=Euro-€

, :

http://www.boogdesign.com/examples/encode/test-get-vs-encodeuri-utf8.html?one=Euro-%E2%82%AC

, , UTF-8, GET encodeURIComponent .

0

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


All Articles