Fix stdin/stdout encoding on Windows. (#2425)

QTextStream uses the system default locale, but this breaks in
various situations: (1) It does not work on the native Windows shell
(cmd.exe, Powershell), since the default Windows locale is Windows-1252,
but the shell uses Windows-850. (2) It also breaks on *nix systems where
the locale is Latin1 or C, which is the case for most CI systems or
build servers.

We allow overriding the detected codec by setting the ENCODING_OVERRIDE
environment variable, but otherwise prefer Windows-850 on Windows and
UTF-8 on any other system, even if LANG is set to something else.

This resolves #2413
This commit is contained in:
Janek Bevendorff 2018-10-28 19:55:00 +01:00 committed by GitHub
parent c9cab250c7
commit 7263dcddfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 180 additions and 61 deletions

View file

@ -21,8 +21,8 @@
#include <stdio.h>
#include <QCommandLineParser>
#include <QTextStream>
#include "cli/TextStream.h"
#include "core/Database.h"
#include "core/Entry.h"
#include "core/Group.h"
@ -41,7 +41,7 @@ Show::~Show()
int Show::execute(const QStringList& arguments)
{
QTextStream out(Utils::STDOUT);
TextStream out(Utils::STDOUT);
QCommandLineParser parser;
parser.setApplicationDescription(description);
@ -78,9 +78,9 @@ int Show::execute(const QStringList& arguments)
int Show::showEntry(Database* database, QStringList attributes, const QString& entryPath)
{
QTextStream in(Utils::STDIN, QIODevice::ReadOnly);
QTextStream out(Utils::STDOUT, QIODevice::WriteOnly);
QTextStream err(Utils::STDERR, QIODevice::WriteOnly);
TextStream in(Utils::STDIN, QIODevice::ReadOnly);
TextStream out(Utils::STDOUT, QIODevice::WriteOnly);
TextStream err(Utils::STDERR, QIODevice::WriteOnly);
Entry* entry = database->rootGroup()->findEntry(entryPath);
if (!entry) {