git-{browser,diff}.cgi: properly decode non-UTF-8git-browser-1.0.0
commit93b50f6751822124b6265b3132c109c8a0e2cdb0
authorKyle J. McKay <mackyle@gmail.com>
Mon, 16 Nov 2020 00:45:07 +0000 (15 17:45 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Mon, 16 Nov 2020 00:45:07 +0000 (15 17:45 -0700)
tree25b8a4071a617ede695858898bb7fa915dbd709c
parentf718df7c9dde3bd233617d1c06994a612b353349
git-{browser,diff}.cgi: properly decode non-UTF-8

The `utf8::valid` function returns true if the internal UTF-8
bit is set OR the string is held as raw bytes.

That's not the correct test to use.  As a result, strings
that were not in UTF-8 format were being returned as-is (i.e.
raw bytes in a non-UTF-8 format) because the `utf8::valid`
would return true (they were held as raw bytes) but then
the `utf8::decode` would fail (leaving them unchanged).

Instead, check the internal flag (`Encode::is_utf8`) and if
it *IS* set _OR_ the string can be decoded by `utf8::decode`
then return the now-decoded-into-internal-utf8-format string.

If that fails go ahead and stuff it through the fallback
decoding and return that.  And make sure the fallback_encoding
initialization does not get stepped on by removing the bogus
assignment in the `my` declaration that takes place _after_
the BEGIN block that does the initialization.

This is how it was meant to work all along.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
git-browser.cgi
git-diff.cgi