在 web2py 请求参数中允许 %20

发布于 2024-12-02 14:31:21 字数 710 浏览 0 评论 0 原文

我正在尝试获取在 URL 中传递编码字符串的请求。例如:

/application/controller/function/hello%20world

这样在我的函数中我可以访问 request.args 并获取一个可以 unquote() 的字符串。

我尝试修改 rewrite.py 以不转换 %20 但这导致了一些错误。其他东西正在我找不到的地方捕获这些请求。我注意到 httpserver.log 文件有:

127.0.0.1, 2011-09-02 00:12:09, GET, /application/controller/function/hello world, HTTP/1.1, 200, 0.169954

空间已经转换。也许这给了一个暗示。网址在哪里未编码?

以下是我的路线文件的内容:

#!/usr/bin/python
# -*- coding: utf-8 -*-

default_application = 'chips'
default_controller = 'default'
default_function = 'index'


routes_onerror = [
   (r'*/404', r'/chips/static/404.html')
   ,(r'*/*',  r'/chips/static/error.html')
]

I am trying to get requests to pass on encoded strings in a URL. For example:

/application/controller/function/hello%20world

so that in my function I can access request.args and get a string that I can unquote().

I tried modifying rewrite.py to not convert %20 but that caused some error. Something else is catching these requests somewhere that I am having trouble finding. I noticed the httpserver.log file has:

127.0.0.1, 2011-09-02 00:12:09, GET, /application/controller/function/hello world, HTTP/1.1, 200, 0.169954

with the space already converted. Maybe that gives a hint. Where are the url's getting unencoded?

Below are the contents of my routes file:

#!/usr/bin/python
# -*- coding: utf-8 -*-

default_application = 'chips'
default_controller = 'default'
default_function = 'index'


routes_onerror = [
   (r'*/404', r'/chips/static/404.html')
   ,(r'*/*',  r'/chips/static/error.html')
]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏末染殇 2024-12-09 14:31:21

默认情况下,web2py 不允许在参数中使用除“@”、“-”、“=”和“.”之外的特殊字符。要覆盖该行为,您可以将以下内容添加到 paths.py:

routes_apps_raw=['chips']

在这种情况下,request.args 将设置为 None,而您可以通过 从 URL 访问原始参数request.raw_args。但请注意,如果您使用 routes_apps_raw 不起作用rel="nofollow">基于参数的重写系统(即,如果您的routes.py 文件包含routers 字典)。

请注意,即使进行了上述更改,web2py 中包含的 Rocket Web 服务器仍会自动 unquote() URL,因此您将在 request.raw_args 中获得特殊字符,但它们已经被解码了。

如果您使用基于参数的重写系统,则可以通过 args_match 键控制 URL 参数中允许使用哪些字符,该键采用正则表达式作为其值。默认正则表达式为 r'([\w@ -]|(?<=[\w@ -])[.=])*$',它允许 '@'、'- '、'=' 和 '.' (对“=”和“.”有一些限制)。

By default, web2py will not allow special characters in args except '@', '-', '=', and '.'. To override that behavior, you can add the following to routes.py:

routes_apps_raw=['chips']

In that case, request.args will be set to None, and instead you can access the raw args from the URL via request.raw_args. Note, though, that routes_apps_raw does not work if you are using the parameter-based rewrite system (i.e., if your routes.py file includes a routers dictionary).

Note, even with the above change, the Rocket web server included with web2py will still automatically unquote() the URL, so you'll get the special characters in request.raw_args, but they will already be decoded.

If you are instead using the parameter-based rewrite system, you can control which characters are allowed in URL args via the args_match key, which takes a regular expression as its value. The default regex is r'([\w@ -]|(?<=[\w@ -])[.=])*$', which allows '@', '-', '=', and '.' (with some restrictions on '=' and '.').

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文