Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2 Fixes/18722.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Wrap file paths containg an ampersand in double quotation marks for running commands in a shell.
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.toCommandArgument = function (this: string): string {
if (!this) {
return this;
}
return this.indexOf(' ') >= 0 && !this.startsWith('"') && !this.endsWith('"') ? `"${this}"` : this.toString();
return (this.indexOf(' ') >= 0 || this.indexOf('&') >= 0) && !this.startsWith('"') && !this.endsWith('"')
? `"${this}"`
: this.toString();
};

/**
Expand Down
4 changes: 4 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,10 @@ suite('String Extensions', () => {
const argTotest = 'one two three';
expect(argTotest.toCommandArgument()).to.be.equal(`"${argTotest}"`);
});
test('Should quote command arguments containing ampersand', () => {
const argTotest = 'one&twothree';
expect(argTotest.toCommandArgument()).to.be.equal(`"${argTotest}"`);
});
test('Should return empty string for empty path', () => {
const fileToTest = '';
expect(fileToTest.fileToCommandArgument()).to.be.equal('');
Expand Down