Fix self-contained handling of ASCII encoding
authorBen Gamari <bgamari.foss@gmail.com>
Fri, 10 Jul 2015 17:49:29 +0000 (19:49 +0200)
committerBen Gamari <ben@smart-cactus.org>
Fri, 10 Jul 2015 17:55:33 +0000 (19:55 +0200)
commitd69dfba4e27c4ec33459906fd87c9a56a371f510
treedd43147a6006ff202153a4868a932129b17eb221
parent9b1ebba2af060fef90dcd722313d3f8041ec5a97
Fix self-contained handling of ASCII encoding

D898 was primarily intended to fix hangs in the event that iconv was
unavailable (namely #10298 and #7695). In addition to this fix, it also
introduced self-contained handling of ANSI terminals to allow compiled
executables to run in minimal environments lacking iconv.

However, the behavior that the patch introduced is highly suspicious.
Specifically, it gives the user a UTF-8 encoding even if they requested
ASCII.

This has the potential to break quite a lot of code. At very least it
breaks GHC's Unicode terminal detection logic, which attempts to catch
an invalid character when encoding a pair of smart-quotes. Of course,
this exception will never be thrown if a UTF-8 encoder is used.

Here we use the `char8` encoding to handle requests for ASCII encodings
in the event that we find iconv to be non-functional.

Fixes #10623.

Test Plan: Validate with T8959a

Reviewers: rwbarton, hvr, austin, hsyl20

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1059

GHC Trac Issues: #10623
libraries/base/GHC/IO/Encoding.hs
libraries/base/GHC/IO/Encoding/Iconv.hs
libraries/base/GHC/TopHandler.hs
testsuite/tests/driver/Makefile
testsuite/tests/driver/T2507.stderr
testsuite/tests/driver/T8959a.stderr