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

Fixed WSL Clipboard Handling #257

Merged
merged 2 commits into from
Jun 18, 2024
Merged

Conversation

vertliba
Copy link
Contributor

@vertliba vertliba commented Mar 24, 2024

This script fixes issues with copying and pasting non-ASCII characters in recent WSL Ubuntu releases.

Key Changes:

Base64 Encoding for Clipboard Operations: I have implemented Base64 encoding for text being copied to and pasted from the clipboard. This approach addresses the issue where special characters could be lost or misinterpreted when transferring data from Windows to Python and vice versa. By encoding the text to Base64 before passing it to Windows and decoding it back after retrieval, we ensure the integrity of the text data, including any special characters.

Implementation Details:

The copy_wsl function now encodes the text to Base64 before creating a PowerShell script to set the clipboard content. This script decodes the Base64 back to text within PowerShell, ensuring that the text placed on the clipboard is exactly as intended.

Similarly, the paste_wsl function retrieves the clipboard content as Base64 encoded text, which is then decoded in Python back to the original text.

Fixes issue #244

@vertliba vertliba closed this Mar 24, 2024
@vertliba vertliba deleted the fix-wsl-encoding branch March 24, 2024 22:28
@vertliba vertliba reopened this Mar 25, 2024
@oallauddin
Copy link

@asweigart Can you review this fix? Having this issue in WSL2.

@oxillix
Copy link

oxillix commented Jun 4, 2024

@asweigart Please review :)

@asweigart asweigart merged commit 4eb7254 into asweigart:master Jun 18, 2024
@asweigart
Copy link
Owner

Tested and it works for me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants