1

If {"foo" => "yo%20daddy"} comes through the url, params[:foo] plays nicely with URI.encode, resolving to:

URI.encode("yo daddy")
#=> "yo%20daddy"

However if "foo" comes as a JSON parameter, it does not.

URI.encode("yo%20daddy")
#=> "yo%2520daddy"

A solution to standardize this is

URI.encode(URI.decode("yo daddy"))
#=> "yo%20daddy"

URI.encode(URI.decode("yo%20daddy"))
#=> "yo%20daddy"

But that seems downright silly. Any better ideas?

MrLore
  • 3,759
  • 2
  • 28
  • 36
gr8scott06
  • 903
  • 1
  • 11
  • 20
  • 1
    I believe the problem is on the client side which is sending URL encoded data as JSON which is incorrect. Rails is decoding / encoding based on what the client says it is sending. So I would ask the client to send the right data or set the correct data-type. – brahmana Sep 18 '14 at 18:53

0 Answers0