html空间显示为%2520而不是%20 [英] A html space is showing as %2520 instead of %20

查看:159
本文介绍了html空间显示为%2520而不是%20的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

传递文件名到firefox浏览器会导致它用%2520 而不是%20 来替换空格。



我在名为 myhtml.html 的文件中有以下HTML:

 < img src =C:\Documents and Settings\screenshots\Image01.png/> 

当我在firefox中加载 myhtml.html 时,图像显示为破碎的图像。所以我右键点击链接查看图片,并显示这个修改后的URL:

  file:/// c:/ Documents %2520and%2520Settings / screenshots / Image01.png 
^
^ ----- Firefox将我的空间改为%2520。

到底是什么?它将我的空间转换为%2520 。它不应该将它转换为%20

如何更改此HTML文件以便浏览器可以找到我的图片?这里发生了什么?

解决方案

稍微解释一下%2520 是:



当您记住自己时,公共空格字符被编码为%20
字符被编码为%25

获得%2520 的方式是当你的url已经有一个%20 ,并再次获得urlencoded,将%20 转换为%2520



您是(或者您可能使用的任何框架)双重编码字符吗?

编辑:
在这方面进行了一些扩展,尤其是对于 LOCAL 链接。假设您要链接到资源 C:\ my path \ my file.html




  • 如果你只提供一个本地文件路径,浏览器需要对所有给出的字符进行编码和保护(在上面的例子中,你应该给它一个空格,因为是一个有效的文件名字符,因此它会被编码)当转换到一个适当的URL(见下一点)。
  • 如果您提供一个URL < c $ c> file:// 协议,你基本上是说你已经采取了一切预防措施并编码了需要编码的东西,其余的应该被视为特殊字符。在上面的例子中,你应该提供 file:/// c:/my%20path/my%20file.html


注意:

ul>

  • 斜杠方向 - 正斜杠 / 用于URL中,反斜杠 \ 在Windows路径中,但大多数客户端将通过将它们转换为适当的正斜杠来使用它们。
  • 另外,协议名称后面有3个斜杠,因为您默默地指向当前机器而不是远程主机(完整的未缩写路径将为 file:// localhost / c:/my%20path/my%file.html ),但是大多数客户端在没有主机部分的情况下也会工作(即只有两个斜杠),假设您是指本地计算机并添加第三个斜线。


  • Passing a filename to the firefox browser causes it to replace spaces with %2520 instead of %20.

    I have the following HTML in a file called myhtml.html:

    <img src="C:\Documents and Settings\screenshots\Image01.png"/>
    

    When I load myhtml.html into firefox, the image shows up as a broken image. So I right click the link to view the picture and it shows this modified URL:

    file:///c:/Documents%2520and%2520Settings/screenshots/Image01.png
                        ^
                        ^-----Firefox changed my space to %2520.
    

    What the heck? It converted my space into a %2520. Shouldn't it be converting it to a %20?

    How do I change this HTML file so that the browser can find my image? What's going on here?

    解决方案

    A bit of explaining as to what that %2520 is :

    The common space character is encoded as %20 as you noted yourself. The % character is encoded as %25.

    The way you get %2520 is when your url already has a %20 in it, and gets urlencoded again, which transforms the %20 to %2520.

    Are you (or any framework you might be using) double encoding characters?

    Edit: Expanding a bit on this, especially for LOCAL links. Assuming you want to link to the resource C:\my path\my file.html:

    • if you provide a local file path only, the browser is expected to encode and protect all characters given (in the above, you should give it with spaces as shown, since % is a valid filename character and as such it will be encoded) when converting to a proper URL (see next point).
    • if you provide a URL with the file:// protocol, you are basically stating that you have taken all precautions and encoded what needs encoding, the rest should be treated as special characters. In the above example, you should thus provide file:///c:/my%20path/my%20file.html. Aside from fixing slashes, clients should not encode characters here.

    NOTES:

    • Slash direction - forward slashes / are used in URLs, reverse slashes \ in Windows paths, but most clients will work with both by converting them to the proper forward slash.
    • In addition, there are 3 slashes after the protocol name, since you are silently referring to the current machine instead of a remote host ( the full unabbreviated path would be file://localhost/c:/my%20path/my%file.html ), but again most clients will work without the host part (ie two slashes only) by assuming you mean the local machine and adding the third slash.

    这篇关于html空间显示为%2520而不是%20的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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