这里出现了非常奇怪的错误。我们正确地收到了类似“/users/8788234”的请求
在 Rails 中我们调用:
redirect_to(:controller => 'login', :from_external_page => true, :on_login => request.env['REQUEST_URI']) and return
我们在 Rails 日志中看到(如我们所料): 重定向到
https://sampleapp.com/login?from_external_page=true&on_login=%2Fusers%2F8788234
但是我们从 IP 看到的下一个请求的查询字符串值被打乱了:
Started GET "/login?from_external_page=gehr&on_login=%2Shfref%2S8788234" for xx.xxx.xxx.xxx at yyyy-mm-dd
这会使查询字符串值变得毫无意义并导致以下错误:
ArgumentError: invalid %-encoding
(%2F 已更改为无效的 %2S)。查询字符串中每个键值对的每个值都移动了 13 个字符。每次我们看到这个,用户代理都会读取:“Mozilla/5.0(兼容;MSIE 9.0;Windows NT 6.1;WOW64;Trident/5.0)”,但我们也看到用户代理成功地导航了应用程序。有没有人见过这样的事情? http://www.whatismybrowser.com/告诉我这个用户代理是在 Windows 7 上运行的 IE9,但我们无法重现该错误。
最佳答案
这肯定是编码问题。我现在正在使用 Rails 4,下面是我当前项目的示例查询字符串。请注意,查询字符串中的第一个参数是“utf8=✓”,您的查询字符串中缺少该参数。
profiles?utf8=✓&min_age=1&max_age=99&min_height=1&max_height=6&min_weight=1&max_weight=400
关于ruby-on-rails - Rails 3 查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22480666/