Parameter separator in URLs, the case of misused question mark

前端 未结 3 1986
無奈伤痛
無奈伤痛 2021-01-11 09:27

What I don\'t really understand is the benefit of using \'?\' instead of \'&\' in urls:

\"question

3条回答
  •  广开言路
    2021-01-11 10:19

    The RFC 3896 (https://www.ietf.org/rfc/rfc3986.txt) defines general and sub delimiters ... '?' is a general, '&' and ';' are sub. The spec is pretty clear about that.

    In this case the latter '?' chars would be treated as part of the query. If the query parser follows the spec strictly, it would then pass the whole query on to the app-destination. If the app-destination could choose to further process the query string in a manner which treats the ? as a param name-value pairs delimiter, that is up to the app's designers.

    My guess is that this often 'just works' because code that splits query strings and the original uri uses all delimiters for matching: 1) first query is split on '?' then 2) query string is parsed using char match list that includes '?' (convenience only).... This could be occurring in ubiquitous parsing libraries already.

提交回复
热议问题