documentcloud/backbone — pull request #1426 by braddunbar (2012-06-18 16:33:20+00:00)
Title: Fragments should be handled encoded.

For the reasons enumerated in #967, url fragments should always be handled in their encoded form. Decoding them makes for impossible comparisons. For instance, decoding the fragment `"search/foo%2Fbar"` using `decodeURIComponent` yields `"search/foo/bar"`, which cannot be meaningfully compared to another fragment because it's not clear which slash should be re-encoded.

This means that fragments should always be encoded before being passed to `History#navigate`. If they aren't, there is no way to compare them to the current fragment.

Also, routes should always get encoded values and decoding should be handled by the user so that `"search/foo%2Fbar/2"` yields the arguments `"foo%2Fbar"` and `"2"` instead of `"foo"` and `"bar"`.

```js
var Router = Backbone.Router.extend({

routes: {
'search/:query/:page': 'search'
},

search: function(query, page) {
query = decodeURIComponent(query);
}

});
```