markevans/dragonfly — pull request #337 by dgiunta (2014-04-03 22:19:41+00:00)
Title: Add the Addressable gem to more responsibly parse uris.

This pull request attempts to resolve the concerns raised in this issue: https://github.com/markevans/dragonfly/issues/336

In a nutshell, the issue is that the URI library—specifically the URI.escape method—does not accept all possible, and valid URIs. The particular problem I was having when I raised the issue was that I had users uploading files with file names that included square brackets.

A lot of google searching later, and I found the following:

1. URI.escape / URI.encode are both deprecated.
2. Documentation on the URI module is actually quite horrible.
3. A commenter [here](http://stackoverflow.com/a/13059657) suggested the [Addressable](https://github.com/sporkmonger/addressable) gem as the best solution as results from that gem conform to RFC 3986, RFC 3987, and RFC 6570 (level 4), whereas URI does not.

I also found looking in the carrierwave source this pull-request and commit: https://github.com/carrierwaveuploader/carrierwave/pull/1013/files#diff-323aa4ff2c24aebdbdd5f21fb1195886R75 which attempt to solve the exact same problem.

Personally, I don't think that's the best solution as it's still using the deprecated URI.encode method.

I'm not sure how you feel about introducing another dependency for the project, but it looks like that might be the best solution.

I think that the Addressable gem might be nice to integrate throughout the gem, but rather than including that work into this pull request, I tried to localize my implementation to just this one particular place that solves this one particular problem, hence my returning the result of URI.parse, instead of converting those URI.parse's into Addressable::URI.parse's throughout.

Thoughts?