Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix https://github.com/microsoft/vscode/issues/180132 #200932

Merged
merged 1 commit into from
Dec 15, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -807,4 +807,8 @@ suite('SnippetParser', () => {
const actual3 = snippet3.toString();
assert.strictEqual(actual3, '.two.one.two.one <> .one.two.one.two');
});

test('Snippet choices are incorrectly escaped/applied #180132', function () {
assertTextAndMarker('${1|aaa$aaa|}bbb\\$bbb', 'aaa$aaabbb$bbb', Placeholder, Text);
});
});
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ export class SnippetString {
}

appendChoice(values: string[], number: number = this._tabstop++): SnippetString {
const value = values.map(s => s.replace(/\$|}|\\|,/g, '\\$&')).join(',');
const value = values.map(s => s.replaceAll(/[|\\,]/g, '\\$&')).join(',');

this.value += '${';
this.value += number;
Expand Down
29 changes: 28 additions & 1 deletion src/vs/workbench/api/test/browser/extHostTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,40 @@ suite('ExtHostTypes', function () {

string = new types.SnippetString();
string.appendText('foo').appendChoice(['far', '$boo']).appendText('bar');
assert.strictEqual(string.value, 'foo${1|far,\\$boo|}bar');
assert.strictEqual(string.value, 'foo${1|far,$boo|}bar');

string = new types.SnippetString();
string.appendText('foo').appendPlaceholder('farboo').appendChoice(['far', 'boo']).appendText('bar');
assert.strictEqual(string.value, 'foo${1:farboo}${2|far,boo|}bar');
});

test('Snippet choices are incorrectly escaped/applied #180132', function () {
{
const s = new types.SnippetString();
s.appendChoice(["aaa$aaa"]);
s.appendText("bbb$bbb");
assert.strictEqual(s.value, '${1|aaa$aaa|}bbb\\$bbb');
}
{
const s = new types.SnippetString();
s.appendChoice(["aaa,aaa"]);
s.appendText("bbb$bbb");
assert.strictEqual(s.value, '${1|aaa\\,aaa|}bbb\\$bbb');
}
{
const s = new types.SnippetString();
s.appendChoice(["aaa|aaa"]);
s.appendText("bbb$bbb");
assert.strictEqual(s.value, '${1|aaa\\|aaa|}bbb\\$bbb');
}
{
const s = new types.SnippetString();
s.appendChoice(["aaa\\aaa"]);
s.appendText("bbb$bbb");
assert.strictEqual(s.value, '${1|aaa\\\\aaa|}bbb\\$bbb');
}
});

test('instanceof doesn\'t work for FileSystemError #49386', function () {
const error = types.FileSystemError.Unavailable('foo');
assert.ok(error instanceof Error);
Expand Down