URL 是否允许包含空格? [英] Is a URL allowed to contain a space?

查看:98
本文介绍了URL 是否允许包含空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

URI(特别是 HTTP URL)是否允许包含一个或多个空格字符?如果一个 URL 必须 被编码,+ 只是一个普遍遵循的约定,还是一个合法的替代方案?

Is a URI (specifically an HTTP URL) allowed to contain one or more space characters? If a URL must be encoded, is + just a commonly followed convention, or a legitimate alternative?

特别是,有人可以指向一个 RFC,表明必须对带有空格的 URL 进行编码吗?

In particular, can someone point to an RFC that indicates that a URL with a space must be encoded?

问题的动机:在对网站进行 Beta 测试时,我注意到一些 URL 中包含空格.Firefox 似乎做对了,这让我感到惊讶!但我希望能够将开发人员指向 RFC,以便他们觉得需要修复这些 URL.

Motivation for question: While beta-testing a web site, I noted that some URLs were constructed with spaces in them. Firefox seemed to do the right thing, which surprised me! But I wanted to be able to point the developers to an RFC so that they would feel the need to fix those URLs.

推荐答案

根据 RFC 1738:

不安全:

由于多种原因,字符可能不安全.空间字符是不安全的,因为重要的空格可能会消失并且转录 URL 时可能会引入无关紧要的空格或排版或受到文字处理程序的处理.字符 "<"">" 是不安全的,因为它们被用作自由文本中 URL 周围的分隔符;引号 (""") 用于在某些系统中分隔 URL.字符 "#" 是不安全的,应该总是被编码,因为它用于万维网和其他将 URL 与片段/锚标识符分隔开的系统跟着它.字符 "%" 是不安全的,因为它用于其他字符的编码.其他字符是不安全的,因为众所周知,网关和其他传输代理有时会修改这样的字符.这些字符是 "{", "}", "|", "", "^", "~","[", "]", and "`".

Characters can be unsafe for a number of reasons. The space character is unsafe because significant spaces may disappear and insignificant spaces may be introduced when URLs are transcribed or typeset or subjected to the treatment of word-processing programs. The characters "<" and ">" are unsafe because they are used as the delimiters around URLs in free text; the quote mark (""") is used to delimit URLs in some systems. The character "#" is unsafe and should always be encoded because it is used in World Wide Web and in other systems to delimit a URL from a fragment/anchor identifier that might follow it. The character "%" is unsafe because it is used for encodings of other characters. Other characters are unsafe because gateways and other transport agents are known to sometimes modify such characters. These characters are "{", "}", "|", "", "^", "~", "[", "]", and "`".

所有不安全的字符都必须始终在 URL 中编码.为了例如,字符 "#" 必须在 URL 中编码,即使是通常不处理片段或锚点的系统标识符,以便如果 URL 被复制到另一个系统中确实使用它们,则无需更改 URL 编码.

All unsafe characters must always be encoded within a URL. For example, the character "#" must be encoded within URLs even in systems that do not normally deal with fragment or anchor identifiers, so that if the URL is copied into another system that does use them, it will not be necessary to change the URL encoding.

这篇关于URL 是否允许包含空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆