目录名称中带有下划线的 URL 编码? [英] URL Encoding with Underscores in a Directory Name?

查看:45
本文介绍了目录名称中带有下划线的 URL 编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在我工作的地方遇到了一个奇怪的争论,我可能错了,所以这就是我问的原因.

We've run into an odd argument where I work, and I may be wrong on this, so this is why I am asking.

我们的软件向 Apache 服务器输出一个目录,该目录将目录名称中的下划线替换为 %5F.

Our software outputs a directory to an Apache server that replaces an underscore with a %5F in the name of the directory.

例如,如果目录名称在我们的软件中作为字符串列出,它将是:andy_test",但是当软件将目录输出到 Apache 服务器时,它会变成andy%5Ftest".不幸的是,当您访问服务器上的 url 时,它最终会变成andy%255Ftest".

For instance if the name of the directory was listed as a string in our software it would be: "andy_test", but then when the software outputs the directory to the Apache server, it would become "andy%5Ftest". Unfortunately, when you access the url on the server it ends up becoming "andy%255Ftest".

不知何故,这对我来说似乎是错误的,再一次的进展是:

Somehow this seems wrong to me, once again the progression is:

  1. andy_test <-(作为软件中的字符串)
  2. andy%5Ftest <-(作为服务器上的目录列出)
  3. andy%255Ftest <-(在从 Web 浏览器调用与服务器上的 URL 相同的目录时必须使用.)

我假设%5"是下划线编码,而%25"是%"编码.

I'm assuming that "%5" is encoding for underscore, and that "%25" is encoding for "%".

现在在我看来,目录名称应在服务器上列出的方式只是简单的 andy_test,如果您使用的是编码的 URI,那么您可能最终会使用andy%5Ftest"来访问apache 服务器上的目录.

Now it would seem to me that the way that the directory name should be listed on the server would be just plain andy_test and if you were using an encoded URI then maybe you would end up with the "andy%5Ftest" to access the directory on the apache server.

我问了后端的人,他们说他们只是:编码任何不是字母或数字的东西.

I asked the guys on the backend about it, and they said that they were just: "encoding anything that was not a letter or a number.

所以我想我对此有点困惑.你能告诉我谁是对的,并指导我了解原因吗?

So I guess I'm a bit confused on this. Can you tell me who is right, and direct me to some information on why?

推荐答案

您不应在创建目录名称时对其进行编码(如您所建议的那样).编码应该只发生在它被分发给浏览器的最后阶段.这就是为什么您最终使用双"编码的原因:%25 是 %,而 5F 是第一次下划线编码的剩余部分.

You should not encode the directory names as you create them (as you suggested). Encoding should only happen at the last stage where it is handed out to the browser. That's why you are ending up with 'double' encoding: %25 is % and 5F is the leftover from the first encoding of underscore.

另外,请注意您不需要根据 rfc1738.

Also, note that you don't need to encode underscores according to rfc1738.

2.2.URL 字符编码问题

2.2. URL Character Encoding Issues

...

因此,只有字母数字、特殊字符$-_.+!*'(),"和可以使用用于其保留目的的保留字符在 URL 中未编码.

Thus, only alphanumerics, the special characters "$-_.+!*'(),", and reserved characters used for their reserved purposes may be used unencoded within a URL.

这篇关于目录名称中带有下划线的 URL 编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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