Skip to content

fix(windows): force UTF-8 console output at startup#744

Open
hoyt-harness wants to merge 1 commit intogoogleworkspace:mainfrom
hoyt-harness:fix/742-utf8-windows-codepage
Open

fix(windows): force UTF-8 console output at startup#744
hoyt-harness wants to merge 1 commit intogoogleworkspace:mainfrom
hoyt-harness:fix/742-utf8-windows-codepage

Conversation

@hoyt-harness
Copy link
Copy Markdown

Summary

Fixes #742.

On Windows, gws inherits the system console codepage (typically CP-1252 or CP-437). When Rust's println! writes UTF-8 bytes, the console interprets them using the active codepage, producing mojibake for any non-ASCII characters in API responses (e.g. smart quotes, accented names, emoji).

Fix: Call SetConsoleOutputCP(65001) via a thin inline FFI shim at the very start of main(), before any output is produced. This tells the Windows Console to interpret subsequent output as UTF-8. The call is gated behind #[cfg(windows)] so non-Windows builds are unaffected.

No new dependency is added — the function is part of kernel32.dll and is called directly via an extern "system" block.

Files changed

File Change
crates/google-workspace-cli/src/output.rs Add set_console_utf8() + Windows-conditional test
crates/google-workspace-cli/src/main.rs Call set_console_utf8() at startup
crates/google-workspace-cli/src/helpers/script.rs Collapse nested if-in-match to satisfy clippy::collapsible_match on latest stable (lint trigger on Rust 1.87+; required for cargo clippy -- -D warnings to pass locally)
.changeset/fix-windows-utf8-console-codepage.md Patch changeset

The script.rs change is a ride-along lint fix — happy to split it into a separate PR if preferred.

Test plan

  • cargo clippy -- -D warnings passes
  • cargo test passes (702 tests pass; 2 pre-existing Windows-only failures in auth::tests::test_get_quota_project_* — those tests set HOME but dirs::home_dir() on Windows uses USERPROFILE, unrelated to this PR)
  • set_console_utf8_sets_codepage_65001 test: calls SetConsoleOutputCP(65001) and then GetConsoleOutputCP() — confirmed returns 65001 on Windows (skips assertion gracefully when no console is attached, e.g. in CI)
  • Binary built and smoke-tested on Windows 11 x86_64

🤖 Generated with Claude Code

…eworkspace#742)

Call SetConsoleOutputCP(65001) via a thin inline FFI wrapper in output.rs
before any output is produced, preventing CP-1252 mojibake for non-ASCII
characters on Windows terminals.

Also collapses a redundant nested if-in-match in helpers/script.rs to
satisfy clippy::collapsible_match, which triggers on the latest stable
toolchain.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 22, 2026

🦋 Changeset detected

Latest commit: 8058aa7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@googleworkspace-bot googleworkspace-bot added the area: core Core CLI parsing, commands, error handling, utilities label Apr 22, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where non-ASCII characters are incorrectly rendered in the Windows console due to legacy codepage inheritance. By explicitly setting the console output to UTF-8 at startup, the application ensures consistent character display across different Windows environments. Additionally, the PR includes a minor refactor to maintain clean code standards and includes a test case to verify the codepage configuration on Windows.

Highlights

  • Windows Console Encoding: Implemented a fix to force the Windows console output codepage to UTF-8 (CP 65001) at application startup, preventing character corruption (mojibake) for non-ASCII output.
  • FFI Implementation: Added a lightweight, platform-specific FFI shim to call the Win32 SetConsoleOutputCP API, ensuring compatibility without introducing external dependencies.
  • Code Cleanup: Refactored conditional logic in script.rs to satisfy the clippy::collapsible_match lint, ensuring compliance with modern Rust standards.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements a fix for Windows console output by forcing the UTF-8 codepage (65001) at startup to prevent character encoding issues. It also refactors the JSON file processing logic in script.rs using match guards for better readability and adds a changeset and unit tests for the new Windows-specific functionality. I have no feedback to provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core CLI parsing, commands, error handling, utilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-ASCII characters in API responses are mangled on Windows when the console codepage is CP-1252 (default)

2 participants