jakubgarfield/Bonobo-Git-Server — pull request #62 by DavidAnson (2013-12-21 06:48:04+00:00)
Title: Follow-up of fix for issue #55: Change the path encoding to be human-rea...

...dable for typical path names

The PathEncoder class is changed from using the "base 64 for URL" encoding to a custom implementation of the conventional "URL/percent encoding" scheme. Per the updated class comments:
/// Avoids triggering IIS's "HTTP Error 404.11 URL Double Escaped" exception
/// (http://support.microsoft.com/kb/942076) for paths with problem characters
/// like '+' by encoding/decoding path fragments in a manner similar to URL
/// encoding (http://en.wikipedia.org/wiki/Percent-encoding) except that '~'
/// is used as the escape character instead of '%' and ' ' is encoded instead
/// of being mapped to '+'. '~' was chosen as the escape character because it
/// avoids the double encoding problem of '%' and is the least commonly used
/// unreserved character in path fragments.

Characters in the RFC 3986 section 2.3 "Unreserved Characters" (http://tools.ietf.org/html/rfc3986) list (ALPHA / DIGIT / '-' / '.' / '_' / '~') are not changed by the new encoding scheme; all other characters are transformed. In particular, '/' and '\' are encoded, so it should be straightforward to fix issue #54 by an encoding of the "name" route parameter similar to how "path" is encoded. (I plan to do this in the next pull request.)

The new encoding means that for all typical cases the URLs for Tree/Blob/Raw controllers are unchanged from before the introduction of PathEncoder and are exact matches of the human-readable names for the corresponding repository files/paths (i.e., "file.txt"=>"file.txt").

The PathEncoderTest class is enhanced with 6 new tests (and 1 tweaked test) to verify the custom encoding implementation behaves correctly. These tests achieve 100% code coverage of the PathEncoder class.

changelog.md is tweaked to note that the fix applies to '&' as well as '+'.