Is EncodeURIComponent really useful?

Something that I still do not understand when making an HTTP request to the server , that the advantage is to use the JS function encodeURIcomponent to encode each http-get component .

While performing some tests, I saw that the server (using PHP) correctly receives the values ​​of the http-get request if I do not use encodeURIcomponent! Obviously, I still need to encode at the client level a special character and? = /: otherwise, an http-get value like this "peace and love = virtue" will be considered as a new pair of http-get request key values ​​instead of a single value. But why does encodeURIcompenent also encode many other characters, such as "Γ¨", for example, which translates to% C3% A8, which must be decoded on the PHP server using the utf8_decode function.

Using encodeURIcomponent, all http-get request values ​​are encoded by utf8, so when I get them in PHP, I have to call the utf8_decode function every time for each $ _GET value, which is quite annoying .

Why can't we just code only and? = /: characters?

see also: The result of JS encodeURIComponent is different from the result generated by FORM It shows that encodeURIComponent does not even encode properly, because the simple FORM GET browser encodes characters like "€" in different ways. So I'm still wondering why this encodeURIComponent is needed?

+3
source share
2 answers

(). , URI ASCII ( , 0-127). , , ASCII, Percent-Encoding.

UTF-8 " ", URI UTF-8. UTF-8 Percent, URI , ASCII.

, http://en.wikipedia.org/wiki/€ UTF-8 € (0xE282AC) (%E2%82%AC). , http://en.wikipedia.org/wiki/€ http://en.wikipedia.org/wiki/%E2%82%AC.

, , http://en.wikipedia.org/wiki/%E2%82%AC , , , http://en.wikipedia.org/wiki/€. , URI UTF-8.

, Percent: , -, Euro. URI €:

<a href="http://en.wikipedia.org/wiki/€">Euro sign</a>

€. , - Windows-1252 ( ), € 0x80, URI http://en.wikipedia.org/wiki/%80 ( , , , Windows-1252 0x80).

ISO 8859-15, € 0xA4, Β€ ISO 8859-1 (Wikipedia ISO 8859-1, 0xA4 UTF-8 HTTP ISO 8859-1 ).

Percent, . , .

+5

,

(URI) [RFC3986] , US-ASCII [ASCII].

unicode ; . RFC. , , . , - , , , .

+7

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


All Articles