perl - Param 导致 Catalyst 出现 "does not map to Unicode"错误

标签 perl unicode catalyst

以下将演示错误:

catalyst.pl Hello
cd Hello
echo "encoding utf8" >> hello.conf
script/hello_server.pl -r

然后在浏览器中导航到 http://localhost:3000/?q=P%E9rl,您将收到 400 Bad Request

似乎是 Catalyst 的 _handle_param_unicode_decoding() 方法产生了这个错误。鉴于此错误很容易生成,它会显示在错误日志中,而 Google 未能修复此错误。我无法阻止用户输入这样的查询字符串。我该如何解决这个问题?

最佳答案

URL 应该使用 UTF-8 编码。 RFC3986:

When a new URI scheme defines a component that represents textual data consisting of characters from the Universal Character Set, the data should first be encoded as octets according to the UTF-8 character encoding; then only those octets that do not correspond to characters in the unreserved set should be percent-encoded.

P E9 r l 不是有效的 UTF-8。

我相信你想要 Pérl(é 是 U+00E9)?那就是

$ perl -Mutf8 -MURI::Escape -E'say uri_escape_utf8("Pérl")'
P%C3%A9rl

400 Bad Request 是提供错误 URL 的适当错误。如果用户不想看到此错误,他们应该使用有效的 URL。您可以使用 handle_unicode_encoding_exception() 覆盖 Catalyst 的默认错误处理行为(例如,提供更精确的错误页面) .

关于perl - Param 导致 Catalyst 出现 "does not map to Unicode"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27624674/

相关文章:

perl - DBIx::Class::Schema::Loader 连接到不同机器上的数据库

perl - 如何在催化剂应用程序上获取 Google OAuth?

perl - 如何从 Perl 控制 Windows GUI 应用程序?

perl - 如何管理开源 Perl 项目使用的模块的安装?

regex - 这是 Perl 智能匹配的预期行为吗?

c - UTF-8 字符串的最小单位有名称吗?

Java Char 到它的 unicode 十六进制字符串表示,反之亦然

arrays - 如何对 Perl 数组进行分页?

java - 通过按位运算将 Unicode 转换为字符

deployment - 无法识别 Catalyst 应用程序 info.plist