Support escapes in markdown destination settings (#200911)

Support escaping `$` to prevent use as variable and escaping `/` inside of transforms
This commit is contained in:
Matt Bierner
2023-12-14 17:02:27 -08:00
committed by GitHub
parent 58bbee628c
commit 9b8f216b8c
2 changed files with 36 additions and 5 deletions

View File

@@ -68,10 +68,31 @@ suite('resolveCopyDestination', () => {
assert.strictEqual(dest.toString(), 'test://projects/project/sub/img.gif');
});
test('transforms should support capture groups', async () => {
test('Transforms should support capture groups', async () => {
const documentUri = vscode.Uri.parse('test://projects/project/sub/readme.md');
const dest = resolveCopyDestination(documentUri, 'img.png', '${fileName/(.+)\\.(.+)/$2.$1/}', () => undefined);
assert.strictEqual(dest.toString(), 'test://projects/project/sub/png.img');
});
test('Should support escaping snippet variables ', async () => {
const documentUri = vscode.Uri.parse('test://projects/project/sub/readme.md');
// Escape leading '$'
assert.strictEqual(
resolveCopyDestination(documentUri, 'img.png', '\\${fileName}', () => undefined).toString(true),
'test://projects/project/sub/${fileName}');
// Escape closing '}'
assert.strictEqual(
resolveCopyDestination(documentUri, 'img.png', '${fileName\\}', () => undefined).toString(true),
'test://projects/project/sub/${fileName\\}');
});
test('Transforms should support escaped slashes', async () => {
const documentUri = vscode.Uri.parse('test://projects/project/sub/readme.md');
const dest = resolveCopyDestination(documentUri, 'img.png', '${fileName/(.+)/x\\/y/}.${fileExtName}', () => undefined);
assert.strictEqual(dest.toString(), 'test://projects/project/sub/x/y.png');
});
});