Always quote Python executable path#964
Conversation
On Windows, this would cause pahts like "C:\Program Files\" to fail launching the Python command as the blank space was not escaped properly. Add also a unit test to validate this change. Signed-off-by: Francesco Giancane <me@fgiancane8.dev>
|
@rchiodo thanks for reviewing the PR! Can you comment on the Unit Tests? They were generated with Copilot so I do not know if that's the best way of testing this case. Thanks! |
|
Yeah the added tests seem fine. I was wondering about the changing of the |
So I am not a TypeScript developer. By far. i have only noticed that the DAP program is now properly quoted. If you know better, I can push another change amending // to . |
|
|
Yeah it's weird that it was there. I'm wondering why. The git blame makes it look like it's been that way since the beginning. Perhaps that code path is never actually used. |
It's only called in |
|
I think we should just remove it. I'm guessing it's not necessary but that it worked in remote scenarios because most of the time people don't do remote between windows machines. |
|
Or maybe even better only do the conversion when the platform isn't windows. I believe there's a 'getOSType' function somewhere. |
Posting a change to be safe and using the non-replace version in our context, just to see if this is what's failing. If you can suggest a snippet using the |
1bcd055 to
10d78b6
Compare
|
Looks like tests are expecting the forward slashes, maybe it's best to revert the last change and just amend test cases? |
|
The tests should special case expected path based on OS |
ok, let me think about it a little bit better. will push new commits once I figure out how to do best. Thanks for all the inputs! |
10d78b6 to
ae8e14f
Compare
There is no need anymore to replace backslashes with forward slashes for paths on Windows, as the Python extension's `toCommandArgumentForPythonExt` function already handles this correctly. Signed-off-by: Francesco Giancane <me@fgiancane8.dev>
| return toCommandArgumentForPythonExt(source).replace(/\\/g, '/'); | ||
|
|
||
| let result = toCommandArgumentForPythonExt(source); | ||
|
|
There was a problem hiding this comment.
I don't think this is the correct change. On non windows machines it may have the wrong path separators.
The unit tests are failing only because the old code did the wrong thing. The unit tests are wrong. They need to be platform specific too.
There was a problem hiding this comment.
Oh ok, I excluded that because I suggested amending previously pushed tests but we discarded that. Let me re-push it once more
There was a problem hiding this comment.
Okay this leaves the 'bug' that was there before. It should be checking OS.
There was a problem hiding this comment.
Ok, restored the OS-checking path as you recommended before.
ae8e14f to
3668184
Compare
I am exploring this scenario. Tests are passing locally. I have to test on a Windows machine to be 100% sure but as far I can see here, 4 tests were failing previously and now the total number of tests match so I'd assume we got it right. I'll keep you posted. Thanks! |
|
So this is the test reportedly failing: The first line is generated using |
Explicitly call `fileToCommandArgumentForPythonExt` when computing a path with spaces and check results are as expected.
| { | ||
| testName: 'When path to debugpy contains spaces', | ||
| path: path.join('path', 'to', 'debugpy', 'with spaces'), | ||
| path: fileToCommandArgumentForPythonExt(path.join('path', 'to', 'debugpy', 'with spaces')), |
There was a problem hiding this comment.
Perhaps something like this?
There was a problem hiding this comment.
I don't feel like this is the right way to test this as you're reusing the internal function to test itself.
There was a problem hiding this comment.
Thought the same, although in the end we want just to validate that the "normalised" input is equivalent. What if we replace(//, ) the input here, simulating the same behaviour, without exposing the internals?
There was a problem hiding this comment.
All in all, it seems to me that the platform-specific behaviour is in path.join
There was a problem hiding this comment.
I'm not sure what you're seeing but my expectation is that fileToCommandArgumentForPythonExt will generate platform specific output. Or at least not change the input path's separator.
The unit tests should be checking that quotes are around a path, they don't really care about the separator in the paths.
There was a problem hiding this comment.
I'm not sure what you're seeing but my expectation is that
fileToCommandArgumentForPythonExtwill generate platform specific output. Or at least not change the input path's separator.The unit tests should be checking that quotes are around a path, they don't really care about the separator in the paths.
So yeah tests data is encoded as "path/to/something/with space" but of course Windows would generate "path\to\something\with spaces".
I kept the sane logic in the source code and updated the test code to use platform-specific data.
We shouldn't be normalizing everything to unix paths in the real code, but in the unit tests is fine. |
…Windows platforms.
This reverts commit 32822e0.
Use backward slashes on Windows and forward slashes on Unix-like OSes when testing correct behavior of path strings quotation.
Added OS-specific logic in test data. Hopefully it's fine now! |
fgiancane8
left a comment
There was a problem hiding this comment.
@rchiodo, I see tests passing as well on my Windows machine. Can we run the CI again?
|
There's still a linter error. If you go to a terminal and run |
Sorry, my bad. Found out later. Should be addressed now! |
On Windows, this would cause pahts like "C:\Program Files" to fail launching the Python command as the blank space was not escaped properly.
Add also a unit test to validate this change.
Please refer to #635, #351 for the initial discussion.