When attempting to attach using PEP 768 style code injection, the code written to the temp file contains invalid characters if the temp file path contains backslashes (such as "C:\Users\xxx\AppData\Local\Temp\")
|
"""import os;os.remove("{tmp_file_path}");""".format( |
This results in an error when the code is attempted to be run:
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape (<string>, line 1)
It looks like this was introduced in c7e86a1. The fix would be to escape the path on Windows when writing the file, or simply replace backslashes with forward slashes.
Environment data
- debugpy version: 1.8.20
- OS and version: Windows 11
- Python version: 3.14.5
- Using VS Code or Visual Studio: VS Code
Actual behavior
Attempting to attach to a Python 3.14 process on Windows where the temp folder has a "\" in the path fails with the error
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape (<string>, line 1)
Expected behavior
It should attach to the process.
Steps to reproduce:
- Start a Python 3.14 process on Windows
- Attempt to attach to it using VS Code
When attempting to attach using PEP 768 style code injection, the code written to the temp file contains invalid characters if the temp file path contains backslashes (such as "C:\Users\xxx\AppData\Local\Temp\")
debugpy/src/debugpy/server/cli.py
Line 468 in 504e23c
This results in an error when the code is attempted to be run:
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape (<string>, line 1)It looks like this was introduced in c7e86a1. The fix would be to escape the path on Windows when writing the file, or simply replace backslashes with forward slashes.
Environment data
Actual behavior
Attempting to attach to a Python 3.14 process on Windows where the temp folder has a "\" in the path fails with the error
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape (<string>, line 1)Expected behavior
It should attach to the process.
Steps to reproduce: