Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Unicode support to CLI on Windows #8618

Merged
merged 5 commits into from
Oct 29, 2022

Conversation

mdonoughe
Copy link
Contributor

On Windows APIs, text is stored in 16-bit wide strings or 8-bit ANSI strings. If you use byte-oriented APIs such as QFile to interact with stdin/stdout/stderr, by default Windows will try to encode text using the ANSI code page. For most users, that's 1252, which cannot represent the characters users typically think of as "Unicode." For backwards compatibility reasons, Windows does not globally switch the ANSI code page to UTF-8, even though UTF-8 has become the de facto 8-bit character encoding.

This PR sets the process code page to UTF-8 for keepassxc-cli.exe (supported since Windows 10 1903) and then ensures that the code page used for console input and output matches the process code page (QTextStream uses the ANSI code page by default and will automatically pick up UTF-8). On older versions of Windows, the code should still work, but only for characters that can be represented by the system ANSI code page.

Fixes #8305

Screenshots

image

Testing strategy

I added an account to the, previously empty, NonAscii.kbdx file and added a new test that executes the CLI binary to read the password. Unlike the other CLI tests, this one needs to execute the CLI as a separate process because of the way the console interaction works.

Type of change

  • ✅ New feature (change that adds functionality)

@droidmonkey
Copy link
Member

Very nice!

tests/CMakeLists.txt Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2022

Codecov Report

Base: 64.25% // Head: 64.29% // Increases project coverage by +0.04% 🎉

Coverage data is based on head (da4db1e) compared to base (a73f5bc).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8618      +/-   ##
===========================================
+ Coverage    64.25%   64.29%   +0.04%     
===========================================
  Files          341      341              
  Lines        44330    44331       +1     
===========================================
+ Hits         28483    28501      +18     
+ Misses       15847    15830      -17     
Impacted Files Coverage Δ
src/cli/Utils.cpp 81.97% <100.00%> (+6.66%) ⬆️
src/core/FileWatcher.cpp 86.75% <0.00%> (+1.20%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mdonoughe
Copy link
Contributor Author

The coverage run failed because of an error in testcli, but it was in testAdd, which I didn't change, on Linux, where my changes to the CLI itself should be removed by the preprocessor.

@droidmonkey
Copy link
Member

Probably a random anomaly, I reran it

@droidmonkey droidmonkey added this to the v2.7.4 milestone Oct 29, 2022
@droidmonkey droidmonkey added platform: Windows feature: CLI pr: backport pending Pull request yet to be backported to a previous release labels Oct 29, 2022
@droidmonkey droidmonkey merged commit ab95690 into keepassxreboot:develop Oct 29, 2022
pull bot pushed a commit to tigerwill90/keepassxc that referenced this pull request Oct 29, 2022
@droidmonkey droidmonkey mentioned this pull request Oct 29, 2022
@droidmonkey droidmonkey added pr: backported Pull request backported to previous release and removed pr: backport pending Pull request yet to be backported to a previous release labels Oct 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: CLI platform: Windows pr: backported Pull request backported to previous release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI: Unicode passwords handling is broken
3 participants