gitweb: workaround surrogate code point problem
commitf5494798e53f6c1d55074576bfb36aea44c7ff55
authorKyle J. McKay <mackyle@gmail.com>
Wed, 8 Apr 2015 16:06:10 +0000 (8 09:06 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Wed, 8 Apr 2015 16:06:10 +0000 (8 09:06 -0700)
treefecb9d629d60a54727f4b3b106ed050143f29d85
parented12be65bfe8284e705d7d51048c77a2ace2a31b
gitweb: workaround surrogate code point problem

When gitweb attempts to automatically treat repository data as
UTF-8, it uses utf8::decode to activate Perl's UTF-8 flag.

Unfortunately, surrogate pairs (codepoints 0xD800-0xDFFF) are
also converted to UTF-8 if present in the input.  However those
codepoints are only valid in UTF-16.  Attempting to do any kind
of pattern match substitution on the strings that contain these
UTF-8 surrogate pair code points will result in a fatal
'Malformed UTF-8 character' error.

The substitution in question is attempting to replace control
characters with nice-looking escapes sequences.  It only needs
to detect character values 0x00-0x1f, so switch into bytes mode
for the substitution to avoid the fatal error.

This results in the surrogates actually being sent back to the
browser for display which typically results in them being
rendered as a replacement character (0xfffd).

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
gitweb/gitweb.perl