未验证 提交 d859157d 编写于 作者: J Johannes Rieken 提交者: GitHub

Merge pull request #81297 from jeanp413/fix-snippet-tranformation-escape

Fix character escaping in snippet transformation
......@@ -664,27 +664,23 @@ export class SnippetParser {
}
private _until(type: TokenType): false | string {
if (this._token.type === TokenType.EOF) {
return false;
}
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();
const start = this._token;
while (this._token.type !== type) {
if (this._token.type === TokenType.EOF) {
return false;
} else if (this._token.type === TokenType.Backslash) {
const nextToken = this._scanner.next();
if (nextToken.type !== TokenType.Dollar
&& nextToken.type !== TokenType.CurlyClose
&& nextToken.type !== TokenType.Backslash) {
return false;
}
}
this._token = this._scanner.next();
}
res += this._scanner.value.substring(pos, this._token.pos);
const value = this._scanner.value.substring(start.pos, this._token.pos).replace(/\\(\$|}|\\)/g, '$1');
this._token = this._scanner.next();
return res;
return value;
}
private _parse(marker: Marker): boolean {
......
......@@ -767,4 +767,17 @@ suite('SnippetParser', () => {
assert.equal((<FormatString>variable.transform!.children[0]).ifValue, 'import { hello } from world');
assert.equal((<FormatString>variable.transform!.children[0]).elseValue, undefined);
});
test('Snippet escape backslashes inside conditional insertion variable replacement #80394', function () {
let snippet = new SnippetParser().parse('${CURRENT_YEAR/(.+)/${1:+\\\\}/}');
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, '\\');
assert.equal((<FormatString>variable.transform!.children[0]).elseValue, undefined);
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册