Skip to content

Commit

Permalink
Enables successful running of python file even when parentheses are p…
Browse files Browse the repository at this point in the history
…resent in the path (microsoft#20414)
  • Loading branch information
enthusiastic2003 authored Dec 23, 2022
1 parent 32f5510 commit 9461f4a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/client/common/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ String.prototype.toCommandArgumentForPythonExt = function (this: string): string
if (!this) {
return this;
}
return (this.indexOf(' ') >= 0 || this.indexOf('&') >= 0) && !this.startsWith('"') && !this.endsWith('"')
return (this.indexOf(' ') >= 0 || this.indexOf('&') >= 0 || this.indexOf('(') >= 0 || this.indexOf(')') >= 0) &&
!this.startsWith('"') &&
!this.endsWith('"')
? `"${this}"`
: this.toString();
};
Expand Down
15 changes: 15 additions & 0 deletions src/test/common/extensions.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ suite('String Extensions', () => {
const argTotest = 'one two three';
expect(argTotest.toCommandArgumentForPythonExt()).to.be.equal(`"${argTotest}"`);
});
test('Should quote file paths containing one of the parentheses: ( ', () => {
const fileToTest = 'user/code(1.py';
expect(fileToTest.fileToCommandArgumentForPythonExt()).to.be.equal(`"${fileToTest}"`);
});

test('Should quote file paths containing one of the parentheses: ) ', () => {
const fileToTest = 'user)/code1.py';
expect(fileToTest.fileToCommandArgumentForPythonExt()).to.be.equal(`"${fileToTest}"`);
});

test('Should quote file paths containing both of the parentheses: () ', () => {
const fileToTest = '(user)/code1.py';
expect(fileToTest.fileToCommandArgumentForPythonExt()).to.be.equal(`"${fileToTest}"`);
});

test('Should quote command arguments containing ampersand', () => {
const argTotest = 'one&twothree';
expect(argTotest.toCommandArgumentForPythonExt()).to.be.equal(`"${argTotest}"`);
Expand Down

0 comments on commit 9461f4a

Please sign in to comment.