Is array syntax using square brackets in URL query strings valid?

后端 未结 6 976
遥遥无期
遥遥无期 2020-12-03 01:21

Is it actually safe/valid to use multidimensional array synthax in the URL query string?

http://example.com?abc[]=123&abc[]=456

It seem

6条回答
  •  孤街浪徒
    2020-12-03 01:29

    I'd ideally like to comment on Ethan's answer really, but don't have sufficient reputation to do it.

    I'm not sure that the relevant part of the WHATWG URL standard is being referenced here. I think the correct part might be in the definition of a valid URL-query string, which it describes as being composed of URL units that themselves are formed from URL code points and percent-encoded bytes. Square brackets are listed within URL code points and thus fall into the percent-encoded bytes category.

    Thus, in answer to the original question, multidimensional array syntax (i.e. using square brackets to represent array indexing) within the query part of the URL is valid, provided the square brackets are percent encoded (as %5B for [ and %5D for ]).

提交回复
热议问题