scientiffic
scientiffic

Reputation: 9415

Error with parsing Rails Params

I'm trying to pass a URL as a param to my Rails app:

Started DELETE "/images/0?s3_filepath=https://s3.amazonaws.com/buildinprogresstest/uploads/blllbyq5k3qinl4l/uploads_2F9qggxxf5dvlsor-667601c8f38d8d41af07828accbf3147_2F2014-07-13%252B18.44.29.jpg" for 127.0.0.1 at 2016-08-31 11:52:09 -0400

The s3_filepath is not being properly parsed in the params:

 Parameters: {"s3_filepath"=>"https://s3.amazonaws.com/buildinprogresstest/uploads/blllbyq5k3qinl4l/uploads_2F9qggxxf5dvlsor-667601c8f38d8d41af07828accbf3147_2F2014-07-13%2B18.44.29.jpg", "id"=>"0"}

If you look closely, the filename includes the sequence "252B18" but the params seems to remove the numbers "52"

I'm at a loss as to why this is happening. Any ideas?

Upvotes: 1

Views: 45

Answers (1)

Michał Młoźniak
Michał Młoźniak

Reputation: 5556

Normally parameters are url-encoded and decoded on rails side. %25 is decoded to %, that's why it is removed from your input. You need to properly encode this url.

In Ruby you can use CGI.escape

CGI.escape "https://s3.amazonaws.com/buildinprogresstest/uploads/blllbyq5k3qinl4l/uploads_2F9qggxxf5dvlsor-667601c8f38d8d41af07828accbf3147_2F2014-07-13%252B18.44.29.jpg"
=> "https%3A%2F%2Fs3.amazonaws.com%2Fbuildinprogresstest%2Fuploads%2Fblllbyq5k3qinl4l%2Fuploads_2F9qggxxf5dvlsor-667601c8f38d8d41af07828accbf3147_2F2014-07-13%25252B18.44.29.jpg"

If you send this request via javascript you can use escape function in javascript

escape("https%3A%2F%2Fs3.amazonaws.com%2Fbuildinprogresstest%2Fuploads%2Fblllbyq5k3qinl4l%2Fuploads_2F9qggxxf5dvlsor-667601c8f38d8d41af07828accbf3147_2F2014-07-13%25252B18.44.29.jpg")

Upvotes: 1

Related Questions