jashkenas/backbone — pull request #3425 by asparagino (2014-12-24 21:19:04+00:00)
Title: Make it possible to decode a url containing an encodeURIComponent encode...

...d % symbol

We've been having problems with params that have been encoded as URI parts with encodeURIComponent. For example:

'http://foo.com/bar/'+encodeURIComponent('foo%/bar')

Somewhere in the router decodeURI is getting called on the URI, then it's throwing a URIError in _extractParameters when decodeURIComponent is getting called on an already decoded % character.

This patch fixes our app by falling back on regex substitutions of URI separators not already decoded by decodeURI when a URIError is thrown. It is still necessary to perform replacements of characters decodeURI does not catch.

Confusingly, the unit test doesn't seem to call decodeURI on the url with the checkURL call, so I've left decodeURIComponent in place rather than avoiding it completely. It would break other tests to remove it and I'm not confident I know all the code paths that call _extractParameters.

Signed-off-by: Pete Setchell