UrlEncoding 安全分隔符
因此,我正在开发的网站有一个过滤系统,该系统通过查询字符串传递键和值系统来进行操作。
整个网站即将进行重构,我正在维护现有网站,因此在我们讨论实现此目的的正确方法之前,我只需要更改分隔符的想法。
当前格式如下:
cf=
问题是,我最近遇到了一个问题,因为此过滤器的一些新值包含 :在其中。即:
cf=MO_AspectRatio:16:10
值正在进行 UrlEncoded,但浏览器正在将 %3a 解码为:动态因为 : 本质上不会破坏网址。
我需要一些关于 :
、-
、_
、&
以外的网址安全分隔符的建议?
这是有道理的。我不是在寻找像 ()
这样的解决方案或一些疯狂的东西。
So the site I'm working on has a filter system that operates by passing a key and value system through a querystring.
The whole site is going through a re-factor soon and I'm maintaining the existing site so before we discuss the RIGHT way to implement this, I just need ideas for changing my delimiter.
The current format is like this:
cf=<key>:<value>
The problem is, I've recently run into an issue because some of our new values for this filter contain :
in them. I.e: cf=MO_AspectRatio:16:10
The value is being UrlEncoded, but the browsers are de-coding %3a into : on the fly because the : doesn't inherently break the urls.
I need some suggestions for url-safe delimiters that aren't :
,-
,_
,&
,?
that makes sense. I'm not looking for a solution like ()
or something wild.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
管子呢?
What about pipe?
这篇维基百科文章对于了解有关非保留字符和保留字符的更多信息非常有用。
到目前为止 波浪号 ~ 可能是最好的选择。但它迟早会破裂的可能性仍然存在。或者您应该根据用户输入正确记录并验证这一点。
This Wikipedia article is useful to learn more about unreserved and reserved characters.
As far the tilde ~ is probably the best option. But the chances are still there that it will break sooner or later. Or you should document and validate that properly on user input.
URI 方案通用语法 允许两个有效的参数分隔符:
&和<代码>;。我总是见过前者,却从未见过后者。需要
?
符号来正确识别查询字符串的开头,因此我不建议使用它。用于 url 的/
也是如此。任何不属于其中之一且不属于您的价值观的角色都是可以接受的。以下是可能的列表,按我自己的喜好排序,不包括您明确拒绝的列表:
,
+
|
#< /code>
$
!
其中任何一个都可以。
另外,即使您明确要求不要:在将来的重构中,请尝试使用真实的 URI 参数(使用 &)。会给你省去很多头痛的事情。
The URI scheme generic syntax admits two valid parameter separators:
&
and;
. I've allways seen the former, and never the later. The?
symbol is needed to correctly identify the start of the query string, so I would not recommend using it. Same goes for the/
, used on urls.Any character that isn't one of those and isn't part of your values is acceptable. Here's a list of possible ones, sorted by my own preference, not including the ones you explicitly rejected:
,
+
|
#
$
!
Any of them should do.
Also, even if you specifically asked not to: In the future refactor, try to use real URI paramters (using &). Will save you lots of headhaches.
最直接的解决方案是对整个字符串进行 Base64 编码,然后在输入时对其进行 Base64 解码。
另一种选择是在输出之前对其进行 urlencode 两次,然后在输入时对其进行 urldecode 一次(php 或 apache 可能不确定谁执行此操作,将对所有输入进行自动 urldecode)。
The most straight forward solution is to base64 encode the entire string, and then base64 decode it on input.
Another option is to urlencode it twice before output, and then urldecode it once on input (There will be an automatic urldecode done on all input by php or maybe apache not sure who does this).