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:
@@ -22,8 +22,8 @@
|
||||
#include "cli/Utils.h"
|
||||
|
||||
#include <QCommandLineParser>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "cli/TextStream.h"
|
||||
#include "core/PasswordGenerator.h"
|
||||
|
||||
Generate::Generate()
|
||||
@@ -38,9 +38,8 @@ Generate::~Generate()
|
||||
|
||||
int Generate::execute(const QStringList& arguments)
|
||||
{
|
||||
QTextStream in(Utils::STDIN, QIODevice::ReadOnly);
|
||||
QTextStream out(Utils::STDOUT, QIODevice::WriteOnly);
|
||||
out.setCodec("UTF-8"); // force UTF-8 to prevent ??? characters in extended-ASCII passwords
|
||||
TextStream in(Utils::STDIN, QIODevice::ReadOnly);
|
||||
TextStream out(Utils::STDOUT, QIODevice::WriteOnly);
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(description);
|
||||
@@ -87,8 +86,7 @@ int Generate::execute(const QStringList& arguments)
|
||||
if (parser.value(len).isEmpty()) {
|
||||
passwordGenerator.setLength(PasswordGenerator::DefaultLength);
|
||||
} else {
|
||||
int length = parser.value(len).toInt();
|
||||
passwordGenerator.setLength(static_cast<size_t>(length));
|
||||
passwordGenerator.setLength(parser.value(len).toInt());
|
||||
}
|
||||
|
||||
PasswordGenerator::CharClasses classes = 0x0;
|
||||
|
||||
Reference in New Issue
Block a user