markevans/dragonfly — pull request #373 by janraasch (2014-11-18 14:34:12+00:00)
Title: Use Base64.urlsafe_encode64

This method complies with
»Base 64 Encoding with URL and Filename Safe Alphabet« in RFC 4648
see http://tools.ietf.org/html/rfc4648#page-7

# Bug
Ran into problems when a Job would serialize to a Base64 string
**containing a slash** (see https://github.com/janraasch/dragonfly/blob/645d6e74aab24386f6cdcdd2c2f6289431447c87/spec/dragonfly/serializer_spec.rb#L17), since apache does not allow slashes in an URI:

From our `var/log/apache2/error.log` log:

```bash
found %2f (encoded '/') in URI (decoded='/media/W1siZiIsInNhbGVzZm9yY2UvdXBsb2Fkcy9zb3VyY2VfZmlsZXMvMDA2TTAwMDAwMEFaRmxXSUFYLXVtbGF1dF/DpCAoMykuemlwIl1d/umlaut_\xc3\xa4.zip'), returning 404
```

# Breaking changes
Nope. Thanks to the proposed implementation of `Dragonfly::Serializer.b64_decode` (https://github.com/janraasch/dragonfly/blob/ac84591b03cab402daa0171345e06dcb08b4ad17/lib/dragonfly/serializer.rb#L19) and `Dragonfly::UrlMapper#init_segments` (https://github.com/janraasch/dragonfly/blob/ac84591b03cab402daa0171345e06dcb08b4ad17/lib/dragonfly/url_mapper.rb#L61) this should be backwards compatible with *urls* encoded with *urlunsafe* `Base64.encode64` and url formats using a `-` like `:job/:name-:size`.

What do you think?