带方括号的编码网址。 Chrome / Firefox / IE中的不同行为 [英] Encoded URL with square brackets. Different behaviour in Chrome/Firefox/IE

查看:228
本文介绍了带方括号的编码网址。 Chrome / Firefox / IE中的不同行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的链接(有点丑,因为它是URL)

 < a href = / items?fc%5B%5D = 12345& amp; fc%5B%5D = 56789& ampf utf8 =%E2%9C%93> foo< / a> 

为了清楚,它是URL编码的,并转换为

 < a href =/ items?fc [] = 12345& fc [] = 56789& utf8 =✓> foo< / a> 

提交表单时,目标网址在不同浏览器中看起来不同:



在Firefox中,它看起来像:

  http:// mydomain / items?fc [] = 12345& fc [] = 56789& utf8 =✓

显示的URL编码,(当使用其中许多时,它给出非常丑陋和非专业的地址)。

  http:// mydomain / items?fc%5B%5D = 12345& fc%5B%5D = 56789& utf8 = ✓

在IE9以上版本中,所有内容都显示为网址编码:

  http:// mydomain / items?fc%5B%5D = 12345& fc%5B%5D = 56789& utf8 =%E2%9C%93 

我可以使用utf8 = ...部分,因为它只是一个问题。
但是没有一个浏览器在处理方面有任何问题,当方括号被显式地输入到URL,所以我不明白为什么Chrome和IE,但不是Firefox必须显示带有URL编码的方括号。



由于表单的html代码在所有浏览器中是相同的,我想这是与浏览器,而不是与网站(在这种情况下,一个Ruby on Rails网站) / p>

编辑:
为了澄清我的实际问题:
为什么这不同?
有没有办法让它看起来不错,至少Chrome?
可以通过在href =...中不进行URL转义来丑陋固定,但我想这是针对URL编码规则?

解决方案

当你想分享这些链接(有状态)时,我认为你期望你的链接将被共享,从网页链接,复制,电子邮件等。



很可能甚至在浏览器之外(例如,你的链接被复制到其他页面,电子邮件等),一些编码会发生。你可能必须接受丑陋会出现在某个地方,如果你必须使用这些字符。


I have a link looking like this (it's a bit ugly because it is URL )

<a href="/items?fc%5B%5D=12345&amp;fc%5B%5D=56789&amp;utf8=%E2%9C%93">foo</a>

To be a bit clear, it is URL encoded and translates to

<a href="/items?fc[]=12345&fc[]=56789&utf8=✓">foo</a>

When the form is submitted, the destination URL looks different in different browsers:

In Firefox, it looks like desired:

http://mydomain/items?fc[]=12345&fc[]=56789&utf8=✓

In Chrome, the square brackets are shown URL-encoded, (which gives very ugly and non-professional looking addresses when using many of them).

http://mydomain/items?fc%5B%5D=12345&fc%5B%5D=56789&utf8=✓

In IE9 (and older) everything is showed URL-encoded:

http://mydomain/items?fc%5B%5D=12345&fc%5B%5D=56789&utf8=%E2%9C%93

I can live with the "utf8=..." part, since it's only a problem in IE. But none of the browsers has any problem with handling when square brackets are explicitly typed into the URL, so i don't understand why Chrome and IE, but not Firefox has to show the brackets with URL encoding.

Since the form's html code is same in all browsers, i suppose that is has to do with the browsers, and not with the site (a Ruby on Rails site in this case)

EDIT: So to clarify my actual questions: Why is this different? Is there a way to make it look good in at least Chrome? It can be ugly-fixed by not URL-escaping in the href="..." but i suppose that is against URL encoding rules?

解决方案

As you want to share these links (with statefulness) I presume you're anticipating your links will be shared, linked from web pages, copied, emailed etc.

It's likely that even outside of the browser (say, where your links are copied into other pages, into emails and so on) that some encoding will occur. You may have to accept ugly will appear somewhere if you have to use those characters.

这篇关于带方括号的编码网址。 Chrome / Firefox / IE中的不同行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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