路径部分中带有//的 URL 是否有效? [英] Is a URL with // in the path-section valid?

查看:41
本文介绍了路径部分中带有//的 URL 是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于网址的问题:

I have a question regarding URLs:

我已经阅读了 RFC 3986 并且仍然对一个 URL 有疑问:

I've read the RFC 3986 and still have a question about one URL:

如果一个 URI 包含一个权限组件,那么路径组件
必须为空或以斜杠 ("/") 字符开头.如果一个 URI不包含权限组件,则路径不能开始
带有两个斜杠字符(//").此外,一个 URI 引用
(第 4.1 节)可能是一个相对路径引用,在这种情况下
第一个路径段不能包含冒号 (":") 字符.ABNF
需要五个单独的规则来消除这些情况的歧义,只有其中之一这将匹配给定 URI 引用中的路径子字符串.我们使用通用术语路径组件"来描述 URI 子字符串
由解析器匹配到这些规则之一.

If a URI contains an authority component, then the path component
must either be empty or begin with a slash ("/") character. If a URI does not contain an authority component, then the path cannot begin
with two slash characters ("//"). In addition, a URI reference
(Section 4.1) may be a relative-path reference, in which case the
first path segment cannot contain a colon (":") character. The ABNF
requires five separate rules to disambiguate these cases, only one of which will match the path substring within a given URI reference. We use the generic term "path component" to describe the URI substring
matched by the parser to one of these rules.

我知道,//server.com:80/path/info 是有效的(它是一个架构相对 URL)

I know, that //server.com:80/path/info is valid (it is a schema relative URL)

我也知道 http://server.com:80/path//info 是有效的.

I also know that http://server.com:80/path//info is valid.

但我不确定以下是否有效:

But I am not sure whether the following one is valid:

http://server.com:80//path/info

我的问题背后的问题是,当由 URI http://创建时,cookie 不会发送到 http://server.com:80//path/info/server.com:80/path/info 限制为 /path

The problem behind my question is, that a cookie is not sent to http://server.com:80//path/info, when created by the URI http://server.com:80/path/info with restriction to /path

推荐答案

参见 带有多个正斜杠的 url,它会破坏什么吗?, 在 URL 中使用双斜杠有什么缺点吗?, URL 中的双斜杠是什么意思?RFC 3986 - 统一资源标识符 (URI):通用语法.

See url with multiple forward slashes, does it break anything?, Are there any downsides to using double-slashes in URLs?, What does the double slash mean in URLs? and RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax.

共识:浏览器将按原样执行请求,他们不会更改请求./ 字符是路径分隔符,但路径段定义为:

Consensus: browsers will do the request as-is, they will not alter the request. The / character is the path separator, but as path segments are defined as:

path-abempty  = *( "/" segment )
segment       = *pchar

表示http://example.com/ 后面的斜线可以直接跟另一个斜线,无止境.服务器可能会忽略它,但浏览器不会,正如您所发现的.

Means the slash after http://example.com/ can directly be followed by another slash, ad infinitum. Servers might ignore it, but browsers don't, as you have figured out.

短语:

如果 URI 不包含权限组件,则路径无法开始带有两个斜杠字符(//").

If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//").

允许 协议相关 URL,但在这种情况下特别声明没有权限(server.com:80 在您的示例中)可能存在.

Allows for protocol-relative URLs, but specifically states in that case no authority (server.com:80 in your example) may be present.

所以:是的,它是有效的,不,不要使用它.

So: yes, it is valid, no, don't use it.

这篇关于路径部分中带有//的 URL 是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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