Apache 模块 request_rec->args 无法处理 url 编码实体

Apache module request_rec->args can't handle url encoded entities

在我的 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' 一样?

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

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

现在我想到了,Apache 不会自动解码 args 参数是有道理的,因为这本质上是 url 的 "data" 部分,与路径无关。