heynemann/ruby-thumbor — pull request #6 by robolson (2012-09-20 02:15:17+00:00)
Title: Spike on escaping the URL used in a watermark filter

I make heavy use of the watermark filter in my codebase that uses Thumbor. As I brought up in [Thumbor issue #99](https://github.com/globocom/thumbor/issues/99) the image URLs used for the watermarks can contain trouble characters like commas and question marks with GET params after them. The solution proposed is to URL encode these characters to prevent interference with the containing URL.

As a result, now anytime I pass a URL to the watermark filter, I encode it first. A simple version of my code looks like this:

```
crypto = Thumbor::CryptoURL.new('secret_key')
crypto.generate({
:width => width,
:height => height,
:image => source,
:filters => "watermark:#{CGI::escape('http://my.domain.com/some/image.url.jpg?123456'),1,2,3"
})
```

Since I am forced to do this for every single URL that I use in a filter, it strikes me that this is something ruby-thumbor could, and maybe should, do for me. I am starting a thread here to discuss it. To make the proposal more concrete I also spiked on a possible implementation which is attached to this pull request.

In the code, I am liberally escaping the entire URL. If only escaping a subset of characters is necessary (e.g. ?, &, comma) then that would be more desirable.

You'll notice I am using an ugly regex to extract the 4 options for the watermark filter. The API for specifying a watermark filter is awfully janky in my opinion. The filter requires 4 options (url, x, y, alpha) and joining them together with commas and passing it all together as a single string is something I might expect to do when communicating over HTTP but not with a ruby library. The single string is prohibitive to work with for both the end-user and the library's developers. I believe that with a better API, the task of adding CGI::escape to the URL would have resulted in a cleaner patch.

Again, I am not expecting this pull request to get merged right away but I would like to get your thoughts on whether ruby-thumbor should take responsibility for escaping watermark urls.