一个点 (%2E) 形式的 url 资源
我有一个资源,它是 .
这意味着我的网址如下所示: http://myapp/index/。
我需要添加查询参数,使其看起来像这样: http://myapp/index/.?type=xml
我使用 Freemarker 来展示我的资源,并针对这种情况进行了百分比编码破解:
<#if key?matches("\\.")>
<li><a href="${contextPath}/index/%2E">${key}</a></li>
</#if>
这对于 Firefox 来说效果很好。但所有其他浏览器,如 IE、Safari、Chrom、Opera 只是忽略我的 url 编码点 (http://myapp/索引/%2E
)。
有什么建议吗?
I have a resource that is a .
This means my url looks like this:http://myapp/index/.
And i need to add query parameters so that it looks like this:http://myapp/index/.?type=xml
I use Freemarker for the presentation of my resources and made a percent-encoding hack for this case:
<#if key?matches("\\.")>
<li><a href="${contextPath}/index/%2E">${key}</a></li>
</#if>
This works fine for Firefox. But all other Browsers like IE, Safari, Chrom, Opera just ignore my url encoded dot (http://myapp/index/%2E
).
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上标准(RFC 3986)中并没有明确说明是否是百分比编码版本
.
或..
应该与未转义版本具有相同的 this-folder/up-a-folder 含义。 3.3节只讲了“路径段.
和..
”,没有明确它们是否匹配.
和.. 在 pct 编码之前或之后。
我个人认为 Firefox 对
%2E
并不意味着.
的解释是最实用的,但不幸的是所有其他浏览器都不同意。这意味着您不能拥有仅包含.
或..
的路径组件。我认为唯一可能的建议是“不要这样做”!还有其他路径组件也很麻烦,通常是由于服务器限制:路径中的
%2F
、%00
和%5C
序列也可能被某些 Web 服务器阻止,空路径段也会导致问题。因此,一般来说,不可能将所有可能的字节序列放入路径组件中。It's actually not really clearly stated in the standard (RFC 3986) whether a percent-encoded version of
.
or..
is supposed to have the same this-folder/up-a-folder meaning as the unescaped version. Section 3.3 only talks about “The path segments.
and..
”, without clarifying whether they match.
and..
before or after pct-encoding.Personally I find Firefox's interpretation that
%2E
does not mean.
most practical, but unfortunately all the other browsers disagree. This would mean that you can't have a path component containing only.
or..
.I think the only possible suggestion is “don't do that”! There are other path components that are troublesome too, typically due to server limitations:
%2F
,%00
and%5C
sequences in paths may also be blocked by some web servers, and the empty path segment can also cause problems. So in general it's not possible to fit all possible byte sequences into a path component.这是不可能的。 §2.3 表示“。”是一个非保留字符,并且“用相应的百分比编码的 US-ASCII 八位字节替换非保留字符的 URI 是等效的”。因此,
/%2E%2E/
与/../
相同,并且将被标准化。(这是 bobince 的回答和 Slowpoison 的评论的组合。)
It is not possible. §2.3 says that "." is an unreserved character and that "URIs that differ in the replacement of an unreserved character with its corresponding percent-encoded US-ASCII octet are equivalent". Therefore,
/%2E%2E/
is the same as/../
, and that will get normalized away.(This is a combination of an answer by bobince and a comment by slowpoison.)