【问题标题】:Apache module request_rec->args can't handle url encoded entitiesApache 模块 request_rec->args 无法处理 url 编码的实体
【发布时间】:2015-04-15 12:55:58
【问题描述】:

在我的 ap_hook_handler 中,当部分查询字符串包含 url 编码实体时,我遇到了 request_rec->args 的奇怪行为。

这是我的发现:

场景#1:编码查询字符串中的第一个'e':

http://localhost/test?group=%65mployees

结果:
r->uri: /test
r->args: "group=           %mployees"(注意很多空格)

场景 #2:编码第二个“e”:

http://localhost/test?group=employ%65es

结果:
r->uri: /test
r->args: "group=employ          0.000000e-01s"

场景#3:编码最后一个'e':

http://localhost/test?group=employe%65s

结果:段错误

当我对路径的任何部分(不是查询字符串)进行 url 编码时,Apache 的行为:

场景#4:在路径中编码'e'而不是查询字符串:

http://localhost/t%65st

结果:
r->uri: /test(预期)
r->args: NULL(预期)

为什么 'args' 和 'uri' 处理 url 编码的方式不同,如何在我的模块中获取规范化的查询字符串,就像使用 'request_rec->uri' 一样?

【问题讨论】:

    标签: apache apache-modules


    【解决方案1】:

    我在日志中得到奇怪结果的原因是我将查询字符串作为参数传递给 printf 并且百分比符号是一个特殊字符。

    我现在正在重构 url,将其传递给 ap_unescape_url 函数以解码 url。

    现在我想起来了,Apache 不会自动解码 args 参数是有道理的,因为这本质上是 url 的“数据”部分,而不是与路径相关的部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-25
      • 2017-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-11
      • 1970-01-01
      • 2014-02-21
      相关资源
      最近更新 更多