Skip to content

🐛 fix(xonsh): retain environment path bytes - #3671

Merged
gaborbernat merged 2 commits into
pypa:mainfrom
gaborbernat:fix/xonsh-legacy-path-3631
Nov 20, 2026
Merged

gaborbernat merged 2 commits into
pypa:mainfrom
gaborbernat:fix/xonsh-legacy-path-3631

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

The Xonsh activation script embedded the destination as Unicode. An environment created under UTF-8 could then activate a different byte-spelled directory when Xonsh ran under ISO-8859-1, putting that directory first on PATH. The script now records non-ASCII destination paths as bytes and decodes them in the sourcing session. Fixes #3631.

Xonsh re-encoded the destination

Python converts environment paths using the process filesystem codec. At generation time, ActivationSelector.create permits shell scripts only when the destination's filesystem bytes match its UTF-8 encoding. For non-ASCII paths, the Xonsh substitution now embeds those bytes for __VIRTUAL_ENV__ as it already did for Tcl and Tk paths. os.fsdecode gives the sourcing session a string that encodes back to the original bytes.

Behavior changes

On POSIX, Xonsh activation keeps the created destination in VIRTUAL_ENV, PATH, and PKG_CONFIG_PATH when the sourcing session uses another filesystem codec. Windows continues to embed the Unicode path. Existing environments need their activation scripts regenerated to receive the fix.

Reported by oss-scanner: ANT-2026-PQW92I38.

@gaborbernat
gaborbernat force-pushed the fix/xonsh-legacy-path-3631 branch from 1273999 to 4871123 Compare November 20, 2026 07:32
@gaborbernat
gaborbernat force-pushed the fix/xonsh-legacy-path-3631 branch 2 times, most recently from 158c5a4 to 78961d9 Compare November 20, 2026 09:09
Xonsh re-encodes the embedded destination with its session's filesystem
codec. After creation under UTF-8, activation under another codec could name
a different directory in PATH.

Record the destination bytes and decode them in the sourcing session, as the
Tcl and Tk paths already do.

Fixes pypa#3631
@gaborbernat
gaborbernat force-pushed the fix/xonsh-legacy-path-3631 branch from 78961d9 to 72c93f4 Compare November 20, 2026 10:43
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 11:17
@gaborbernat
gaborbernat merged commit abf69ff into pypa:main Nov 20, 2026
81 checks passed
@gaborbernat
gaborbernat deleted the fix/xonsh-legacy-path-3631 branch November 23, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Xonsh activation selects wrong PATH directory after locale change

1 participant