本文介绍了分号作为URL查询分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

删除了死的Imageshack链接 - &符号与分号

虽然强烈建议(,来自)对于Web服务器来说,支持分号作为URL查询项的分隔符(除了&符号)之外,似乎一般都没有遵循。

Although it is strongly recommended (W3C source, via Wikipedia) for web servers to support semicolon as a separator of URL query items (in addition to ampersand), it does not seem to be generally followed.

例如,比较

        http://www.google.com/search?q=nemo&oe=utf-8

        http://www.google.com/search?q=nemo;oe=utf-8

结果。 (在后一种情况下,分号是,或者在撰写本文时,被视为普通字符串字符,就像网址是:)

results. (In the latter case, semicolon is, or was at the time of writing this text, treated as ordinary string character, as if the url was: http://www.google.com/search?q=nemo%3Boe=utf-8)

虽然我尝试了第一个URL解析库,但表现还不错:

Although the first URL parsing library i tried, behaves well:

>>> from urlparse import urlparse, query_qs
>>> url = 'http://www.google.com/search?q=nemo;oe=utf-8'
>>> parse_qs(urlparse(url).query)
{'q': ['nemo'], 'oe': ['utf-8']}

接受分号作为分隔符的当前状态是什么,哪些是潜在的问题或一些有趣的注释? (从服务器和客户端的角度来看)

What is the current status of accepting semicolon as a separator, and what are potential issues or some interesting notes? (from both server and client point of view)

推荐答案

已经过时。根据,分号现在是非法作为参数分隔符:

The W3C Recommendation from 1999 is obsolete. The current status, according to the 2014 W3C Recommendation, is that semicolon is now illegal as a parameter separator:


  1. 让字符串成为严格拆分U + 0026 AMPERSAND字符(&)上字符串有效负载的结果。


换句话说,?foo = bar; baz 表示参数 foo 的值为 bar; baz ;而?foo = bar; baz = sna 应导致 foo bar; baz = sna (虽然技术上非法,因为第二个 = 应该转义为%3D )。

In other words, ?foo=bar;baz means the parameter foo will have the value bar;baz; whereas ?foo=bar;baz=sna should result in foo being bar;baz=sna (although technically illegal since the second = should be escaped to %3D).

这篇关于分号作为URL查询分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 21:18