mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
CLI: Add Unicode support on Windows (#8618)
This commit is contained in:
parent
37baa6fd25
commit
ab95690043
@ -65,6 +65,9 @@ install(TARGETS keepassxc-cli
|
||||
RUNTIME DESTINATION ${CLI_INSTALL_DIR} COMPONENT Runtime)
|
||||
|
||||
if(WIN32)
|
||||
target_sources(keepassxc-cli
|
||||
PRIVATE keepassxc-cli.exe.manifest)
|
||||
|
||||
# install(CODE "include(BundleUtilities)
|
||||
# fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/keepassxc-cli.exe\" \"\" \"\")"
|
||||
# COMPONENT Runtime)
|
||||
|
@ -63,6 +63,13 @@ namespace Utils
|
||||
fd->open(fopen("/dev/null", "w"), QIODevice::WriteOnly);
|
||||
#endif
|
||||
DEVNULL.setDevice(fd);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
// On Windows, we ask via keepassxc-cli.exe.manifest to use UTF-8,
|
||||
// but the console code-page isn't automatically changed to match.
|
||||
SetConsoleCP(GetACP());
|
||||
SetConsoleOutputCP(GetACP());
|
||||
#endif
|
||||
}
|
||||
|
||||
void setStdinEcho(bool enable = true)
|
||||
|
8
src/cli/keepassxc-cli.exe.manifest
Normal file
8
src/cli/keepassxc-cli.exe.manifest
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<application>
|
||||
<windowsSettings>
|
||||
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
</assembly>
|
@ -235,6 +235,7 @@ endif()
|
||||
|
||||
add_unit_test(NAME testcli SOURCES TestCli.cpp
|
||||
LIBS testsupport cli ${TEST_LIBRARIES})
|
||||
target_compile_definitions(testcli PRIVATE KEEPASSX_CLI_PATH="$<TARGET_FILE:keepassxc-cli>")
|
||||
|
||||
if(WITH_GUI_TESTS)
|
||||
add_subdirectory(gui)
|
||||
|
@ -102,6 +102,9 @@ void TestCli::init()
|
||||
m_yubiKeyProtectedDbFile.reset(new TemporaryFile());
|
||||
m_yubiKeyProtectedDbFile->copyFromFile(file.arg("YubiKeyProtectedPasswords.kdbx"));
|
||||
|
||||
m_nonAsciiDbFile.reset(new TemporaryFile());
|
||||
m_nonAsciiDbFile->copyFromFile(file.arg("NonAscii.kdbx"));
|
||||
|
||||
m_stdout.reset(new QBuffer());
|
||||
m_stdout->open(QIODevice::ReadWrite);
|
||||
Utils::STDOUT.setDevice(m_stdout.data());
|
||||
@ -2316,6 +2319,29 @@ void TestCli::testYubiKeyOption()
|
||||
QCOMPARE(m_stdout->readAll(), QByteArray());
|
||||
}
|
||||
|
||||
void TestCli::testNonAscii()
|
||||
{
|
||||
QProcess process;
|
||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
||||
process.start(
|
||||
KEEPASSX_CLI_PATH,
|
||||
QStringList(
|
||||
{"show", "-a", "password", m_nonAsciiDbFile->fileName(), QString::fromUtf8("\xe7\xa7\x98\xe5\xaf\x86")}));
|
||||
process.waitForStarted();
|
||||
QCOMPARE(process.state(), QProcess::ProcessState::Running);
|
||||
|
||||
// Write password.
|
||||
process.write("\xce\x94\xc3\xb6\xd8\xb6\n");
|
||||
process.closeWriteChannel();
|
||||
|
||||
process.waitForFinished();
|
||||
|
||||
process.readLine(); // skip password prompt
|
||||
QByteArray password = process.readLine();
|
||||
QCOMPARE(QString::fromUtf8(password).trimmed(),
|
||||
QString::fromUtf8("\xf0\x9f\x9a\x97\xf0\x9f\x90\x8e\xf0\x9f\x94\x8b\xf0\x9f\x93\x8e"));
|
||||
}
|
||||
|
||||
void TestCli::testCommandParsing_data()
|
||||
{
|
||||
QTest::addColumn<QString>("input");
|
||||
|
@ -80,6 +80,7 @@ private slots:
|
||||
void testShow();
|
||||
void testInvalidDbFiles();
|
||||
void testYubiKeyOption();
|
||||
void testNonAscii();
|
||||
|
||||
private:
|
||||
QScopedPointer<QFile> m_devNull;
|
||||
@ -90,6 +91,7 @@ private:
|
||||
QScopedPointer<TemporaryFile> m_keyFileProtectedDbFile;
|
||||
QScopedPointer<TemporaryFile> m_keyFileProtectedNoPasswordDbFile;
|
||||
QScopedPointer<TemporaryFile> m_yubiKeyProtectedDbFile;
|
||||
QScopedPointer<TemporaryFile> m_nonAsciiDbFile;
|
||||
|
||||
QScopedPointer<QBuffer> m_stdout;
|
||||
QScopedPointer<QBuffer> m_stderr;
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user