Why doesn't Twitter and Google API documentation encode ampersands in URLs?

前端 未结 2 2106
后悔当初
后悔当初 2021-02-19 09:14

I have read I should encode my ampersands as & in HTML.
However numerous code samples from respected companies somehow forget

2条回答
  •  无人共我
    2021-02-19 10:02

    Two different contexts here.

    1. Within the context of a javascript href, the & is just fine and should not be encoded.
    2. In an HTML link the & is forbidden and should be escaped.

    In the HTML link context an HTML character entity will be decoded before the address is passed to the HTTP process; a URL-encoded character will not, as the server can read it directly.

提交回复
热议问题