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

前端 未结 2 2113
后悔当初
后悔当初 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 09:46

    Is there any real benefit from not escaping ampersand in links?

    It saves a few keystrokes.

    Is this related to browser quirks?

    No

    Is this just a mistake in documentation?

    Yes

    Is there a reason API documentation by respectable companies often violates this rule?

    Ignorance and/or laziness. Browsers perform error recovery so they either don't notice the errors or they don't care. The documentation probably isn't written by their best experts.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题