Skip to content

Commit

Permalink
fix #78883
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Aug 12, 2019
1 parent 4eb850d commit 756c90d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/vs/editor/contrib/snippet/snippetParser.ts
Expand Up @@ -667,16 +667,24 @@ export class SnippetParser {
if (this._token.type === TokenType.EOF) {
return false;
}
let start = this._token;
while (this._token.type !== type) {
let res = '';
let pos = this._token.pos;
let prevToken = <Token>{ type: TokenType.EOF, pos: 0, len: 0 };

while (this._token.type !== type || prevToken.type === TokenType.Backslash) {
if (this._token.type === type) {
res += this._scanner.value.substring(pos, prevToken.pos);
pos = this._token.pos;
}
prevToken = this._token;
this._token = this._scanner.next();
if (this._token.type === TokenType.EOF) {
return false;
}
}
let value = this._scanner.value.substring(start.pos, this._token.pos);
res += this._scanner.value.substring(pos, this._token.pos);
this._token = this._scanner.next();
return value;
return res;
}

private _parse(marker: Marker): boolean {
Expand Down
13 changes: 13 additions & 0 deletions src/vs/editor/contrib/snippet/test/snippetParser.test.ts
Expand Up @@ -754,4 +754,17 @@ suite('SnippetParser', () => {
let snippet = new SnippetParser().parse('namespace ${TM_DIRECTORY/[\\/]/\\\\/g};');
assertMarker(snippet, Text, Variable, Text);
});

test('Snippet cannot escape closing bracket inside conditional insertion variable replacement #78883', function () {

let snippet = new SnippetParser().parse('${TM_DIRECTORY/(.+)/${1:+import { hello \\} from world}/}');
let variable = <Variable>snippet.children[0];
assert.equal(snippet.children.length, 1);
assert.ok(variable instanceof Variable);
assert.ok(variable.transform);
assert.equal(variable.transform!.children.length, 1);
assert.ok(variable.transform!.children[0] instanceof FormatString);
assert.equal((<FormatString>variable.transform!.children[0]).ifValue, 'import { hello } from world');
assert.equal((<FormatString>variable.transform!.children[0]).elseValue, undefined);
});
});

0 comments on commit 756c90d

Please sign in to comment.