以下将演示错误:
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/