Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 25, 2025

The Jupyter extension was failing on Windows when usernames contained special characters like parentheses, ampersands, or other shell metacharacters. This occurred because executable paths weren't being properly quoted during process execution.

Problem

When Windows usernames contain special characters (e.g., John(Contractor)), the extension would fail with errors like:

'c:\Users\John' is not recognized as an internal or external command,
operable program or batch file.

This happened because the toCommandArgument() function only checked for spaces but ignored other shell metacharacters like parentheses (), ampersands &, pipes |, etc.

Root Cause

The issue was in src/platform/common/helpers.ts where toCommandArgument() used:

return value.indexOf(' ') >= 0 && !value.startsWith('"') && !value.endsWith('"') ? `"${value}"` : value.toString();

This meant paths like C:\Users\John(Contractor)\AppData\Local\env\python.exe were not being quoted, causing Windows command shell to split the path at the first space or special character.

Solution

Updated toCommandArgument() to check for all shell metacharacters that require quoting:

const needsQuoting = /[\s()&|<>^]/.test(value);
return needsQuoting && !value.startsWith('"') && !value.endsWith('"') ? `"${value}"` : value.toString();

Now paths with any special characters are properly quoted as "C:\Users\John(Contractor)\AppData\Local\env\python.exe".

Testing

Added comprehensive test coverage for:

  • Windows paths with spaces in usernames
  • Windows paths with parentheses (the specific issue case)
  • Paths with other shell metacharacters (&, |, <, >, ^)
  • Already quoted paths (prevents double-quoting)
  • Normal paths without special characters

All existing tests continue to pass, ensuring no regressions.

Fixes #16932.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits August 25, 2025 12:52
- Updated toCommandArgument() to quote paths with parentheses and other shell metacharacters
- Added comprehensive tests for Windows paths with special characters
- Ensures proper quoting for paths like C:\Users\John(Contractor)\AppData\Local\env\python.exe

Co-authored-by: DonJayamanne <1948812+DonJayamanne@users.noreply.github.com>
Co-authored-by: DonJayamanne <1948812+DonJayamanne@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Jupyter extension fails with Windows usernames containing special characters Fix Windows path quoting for usernames with special characters Aug 25, 2025
@Copilot Copilot AI requested a review from DonJayamanne August 25, 2025 12:54
Copilot finished work on behalf of DonJayamanne August 25, 2025 12:54
@DonJayamanne DonJayamanne marked this pull request as ready for review August 25, 2025 19:58
@vs-code-engineering vs-code-engineering bot added this to the August 2025 milestone Aug 25, 2025
@DonJayamanne DonJayamanne enabled auto-merge (squash) August 25, 2025 20:12
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.

Jupyter extension fails with Windows usernames containing special characters
3 participants