在配置/ routes.rb中:
get 'books(/*anything)' => redirect( "/public/%{anything}" ), :format => false
在规格/请求/ store_request_spec.rb:
get '/books/aoeu/snth'
expect(response).to redirect_to( '/public/aoeu/snth' )
这种失败:
Failure/Error: expect(response).to redirect_to( '/public/aoeu/snth' )
Expected response to be a redirect to <http://www.example.com/public/aoeu/snth> but was a redirect to <http://www.example.com/public/aoeu%2Fsnth>.
Expected "http://www.example.com/public/aoeu/snth" to be === "http://www.example.com/public/aoeu%2Fsnth".
# ./spec/requests/store_request_spec.rb:14:in `block (3 levels) in <top (required)>'
为何%2F被插入到重定向响应,如何预防呢?
编辑:
如果我使用:
get 'books(/*anything)' => redirect( CGI::unescape("/public/%{anything}") ), :format => false
创建一个转义字符串我仍然得到同样的错误。