Skip to content

Commit 9461f4a

Browse files
Enables successful running of python file even when parentheses are present in the path (microsoft#20414)
1 parent 32f5510 commit 9461f4a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/client/common/extensions.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ String.prototype.toCommandArgumentForPythonExt = function (this: string): string
7373
if (!this) {
7474
return this;
7575
}
76-
return (this.indexOf(' ') >= 0 || this.indexOf('&') >= 0) && !this.startsWith('"') && !this.endsWith('"')
76+
return (this.indexOf(' ') >= 0 || this.indexOf('&') >= 0 || this.indexOf('(') >= 0 || this.indexOf(')') >= 0) &&
77+
!this.startsWith('"') &&
78+
!this.endsWith('"')
7779
? `"${this}"`
7880
: this.toString();
7981
};

src/test/common/extensions.unit.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ suite('String Extensions', () => {
2020
const argTotest = 'one two three';
2121
expect(argTotest.toCommandArgumentForPythonExt()).to.be.equal(`"${argTotest}"`);
2222
});
23+
test('Should quote file paths containing one of the parentheses: ( ', () => {
24+
const fileToTest = 'user/code(1.py';
25+
expect(fileToTest.fileToCommandArgumentForPythonExt()).to.be.equal(`"${fileToTest}"`);
26+
});
27+
28+
test('Should quote file paths containing one of the parentheses: ) ', () => {
29+
const fileToTest = 'user)/code1.py';
30+
expect(fileToTest.fileToCommandArgumentForPythonExt()).to.be.equal(`"${fileToTest}"`);
31+
});
32+
33+
test('Should quote file paths containing both of the parentheses: () ', () => {
34+
const fileToTest = '(user)/code1.py';
35+
expect(fileToTest.fileToCommandArgumentForPythonExt()).to.be.equal(`"${fileToTest}"`);
36+
});
37+
2338
test('Should quote command arguments containing ampersand', () => {
2439
const argTotest = 'one&twothree';
2540
expect(argTotest.toCommandArgumentForPythonExt()).to.be.equal(`"${argTotest}"`);

0 commit comments

Comments
 (0)