Fix PowerShell path quoting in env activate - #11059
Open
lllleolin-max wants to merge 1 commit into
Open
Conversation
Use literal PowerShell strings for activation paths on every platform and escape ordinary and smart single-quote delimiters. Assisted-by: OpenAI GPT-6 <noreply@openai.com>
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. This changes how environment paths are parsed by PowerShell, including escaping characters that can otherwise trigger variable expansion or command substitution. If the quoting is wrong, a generated activation command could execute unintended PowerShell content; reverting would prevent future occurrences but could not undo a command already run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
poetry env activatecurrently double-quotes PowerShell activation paths on Windows. PowerShell expands variables and subexpressions and interprets backticks inside those quotes, so a project directory such as$variable,$(1+1), orback`tickproduces a command that cannot find its activation script. On other platforms, the POSIX quoting fallback also does not provide PowerShell's escaping for embedded apostrophes.Use PowerShell single-quoted strings for both
powershellandpwshon every platform, doubling embedded single-quote delimiters, including the smart quotes recognized by PowerShell. Add regression coverage for spaces, interpolation characters, backticks, ordinary apostrophes, and the four smart single quotes, with both values of the Windows flag.Validation:
pytest tests/console/commands/env -n 0 --randomly-seed=0 -q: 79 passed.activate.ps1scripts under 11 different directory names in Windows PowerShell 5.1.26100.9444 and PowerShell 7.6.5. Each shell passed 8/11 cases before the fix and 11/11 after it; the three failures before the fix were the variable, subexpression, and backtick paths.Tests used the checked-out source via
PYTHONPATH=srcon Windows/Python 3.12.14. The full Poetry suite and native Linux/macOS runs were not performed.This bug was found during source review; there is no associated issue.
Pull Request Check List
AI assistance: OpenAI Codex helped implement and validate this change.