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

Incorrect Clipboard Text Encoding when LANG Environment Variable is Empty on macOS #4132

Open
wrtx-dev opened this issue Mar 12, 2025 · 0 comments
Labels
Bug Something isn't working

Comments

@wrtx-dev
Copy link

Description

When the LANG environment variable is empty on macOS, the runtime.ClipboardGetText function in Go Wails returns incorrectly encoded text (often mojibake) from the clipboard. This issue occurs because the underlying pbpaste command relies on the LANG environment variable to determine the correct character encoding. If LANG is not set, pbpaste defaults to an encoding that is incompatible with UTF-8, leading to incorrect text when the Go Wails application expects UTF-8.

This issue only appears in released (packaged) versions of the application. In development mode, the LANG environment variable is typically inherited from the terminal, so the problem does not occur.

To Reproduce

  1. Create a Go Wails application that uses the runtime.ClipboardGetText function to read text from the clipboard.
    Ensure the macOS system is configured such that the LANG environment variable is not set in the application's environment. This can be achieved by building a release version and running it as a standalone application (i.e., not from a terminal that sets the LANG variable).
  2. Copy text containing non-ASCII characters (e.g., Chinese, Japanese, accented characters) to the clipboard.
  3. Paste the text into the Go Wails application using the clipboard functionality.
  4. Observe that the text is displayed as mojibake or otherwise incorrectly encoded.

Expected behaviour

The runtime.ClipboardGetText function should always return correctly encoded text from the clipboard, regardless of the LANG environment variable. It should either:

Correctly handle cases where LANG is not set.
Ensure that the application has a valid LANG environment variable set (e.g., by setting it programmatically or in the application's Info.plist).

The code is here

Alternatively, you can easily observe the behavior of the pbpaste command using the following command:

Image

Screenshots

No response

Attempted Fixes

No response

System Details

# Wails
Version | v2.9.3

# System
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
| OS           | MacOS                                                                                                                   |
| Version      | 15.3.1                                                                                                                  |
| ID           | 24D70                                                                                                                   |
| Go Version   | go1.23.3                                                                                                                |
| Platform     | darwin                                                                                                                  |
| Architecture | amd64                                                                                                                   |
| CPU          | Apple M4                                                                                                                |
| GPU          | Chipset Model: Apple M4 Type: GPU Bus: Built-In Total Number of Cores: 10 Vendor: Apple (0x106b) Metal Support: Metal 3 |
| Memory       | 16GB                                                                                                                    |
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌────────────────────────────────────────────────────────────────┐
| Dependency                | Package Name | Status    | Version |
| Xcode command line tools  | N/A          | Installed | 2409    |
| Nodejs                    | N/A          | Installed | 22.11.0 |
| npm                       | N/A          | Installed | 10.9.0  |
| *Xcode                    | N/A          | Available |         |
| *upx                      | N/A          | Available |         |
| *nsis                     | N/A          | Available |         |
└─────────────────── * - Optional Dependency ────────────────────┘

# Diagnosis
Optional package(s) installation details:
  - Xcode: Available at https://apps.apple.com/us/app/xcode/id497799835
  - upx : Available at https://upx.github.io/
  - nsis : More info at https://wails.io/docs/guides/windows-installer/

 SUCCESS  Your system is ready for Wails development!

 ♥   If Wails is useful to you or your company, please consider sponsoring the project:
https://github.com/sponsors/leaanthony

Additional context

No response

@wrtx-dev wrtx-dev added the Bug Something isn't working label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant