I am getting this error when sending POST data to a Rails app, the data is XML.
!! Unexpected error while processing request: invalid %-encoding (bplist00� !"#$%)
The problem is I can't change the data that is coming in (it works fine on a PHP app and now I need to parse it in our Rails app) but I don't get to see the data at all, this error is thrown in the development console running Rails (nothing is logged), I don't even get to the controllers so I can at least output it to see what might be wrong with it or catch the data and convert it.
It seems I don't even get to the route level since removing the route that is supposed to catch the request makes no difference, I get the same error. I read somewhere that it could be a malfomed URL but have no way of knowing that if I cannot see the incoming data.
So my questions are:
- How can I fix this?
- Is there a way to view this post data somehow?
- What tools or stategies can I use to troubleshoot this?
I also read that the Rack middleware was catching the error but I know nothing about Rack or how I would prevent it from catching this and simply pass it on.
Thanks.
PS I know there are similar questions here but none of them shed any light on how to fix or troubleshoot the error.
Got a bit farther:
By putting this into my application.rb
file:
module Rack::Utils
def unescape(s, encoding = Encoding::UTF_8)
begin
URI.decode_www_form_component(s, encoding)
rescue
Rails.logger.warn "DECODING on #{s.inspect} with #{encoding.inspect} FAILING."
end
end
module_function :unescape
end
I'm able to see that what's coming in is the following in the development log:
DECODING on "bplist00\xDF\x10\x1C\x01\x02\x03\x04\x05\x06\a\b\t\n\v\f\r\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\e\x1C\x1D\x1E\x1F !\"\#$%" with #<Encoding:UTF-8> FAILING.
Any ideas on how to parse this?