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

Ensures activate.bat can handle Unicode contents #2416

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/2416.feature.rst
@@ -0,0 +1 @@
Ensures activate.bat can handle Unicode contents - by :user:`OmerFI`.
13 changes: 13 additions & 0 deletions src/virtualenv/activation/batch/activate.bat
@@ -1,3 +1,11 @@
@REM This file is UTF-8 encoded, so we need to update the current code page while executing it
@for /f "tokens=2 delims=:." %%a in ('"%SystemRoot%\System32\chcp.com"') do @(
@set _OLD_CODEPAGE=%%a
)
@if defined _OLD_CODEPAGE (
"%SystemRoot%\System32\chcp.com" 65001 > nul
)

@set "VIRTUAL_ENV=__VIRTUAL_ENV__"

@if defined _OLD_VIRTUAL_PROMPT (
Expand Down Expand Up @@ -35,3 +43,8 @@
:ENDIFVPATH2

@set "PATH=%VIRTUAL_ENV%\__BIN_NAME__;%PATH%"

@if defined _OLD_CODEPAGE (
"%SystemRoot%\System32\chcp.com" %_OLD_CODEPAGE% > nul
@set _OLD_CODEPAGE=
)
3 changes: 1 addition & 2 deletions tests/unit/activation/test_batch.py
Expand Up @@ -21,8 +21,7 @@ def __init__(self, session):
self.unix_line_ending = False

def _get_test_lines(self, activate_script):
# for BATCH utf-8 support need change the character code page to 650001
return ["@echo off", "", "chcp 65001 1>NUL"] + super()._get_test_lines(activate_script)
return ["@echo off", ""] + super()._get_test_lines(activate_script)

def quote(self, s):
"""double quotes needs to be single, and single need to be double"""
Expand Down