mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 02:58:56 +01:00
Fix #46644
This commit is contained in:
@@ -118,9 +118,9 @@ function pathToSuggestion(p: string, replaceRange: Range): CompletionItem {
|
||||
|
||||
if (isDir) {
|
||||
return {
|
||||
label: p,
|
||||
label: escapePath(p),
|
||||
kind: CompletionItemKind.Folder,
|
||||
textEdit: TextEdit.replace(replaceRange, p),
|
||||
textEdit: TextEdit.replace(replaceRange, escapePath(p)),
|
||||
command: {
|
||||
title: 'Suggest',
|
||||
command: 'editor.action.triggerSuggest'
|
||||
@@ -128,13 +128,18 @@ function pathToSuggestion(p: string, replaceRange: Range): CompletionItem {
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
label: p,
|
||||
label: escapePath(p),
|
||||
kind: CompletionItemKind.File,
|
||||
textEdit: TextEdit.replace(replaceRange, p)
|
||||
textEdit: TextEdit.replace(replaceRange, escapePath(p))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Escape https://www.w3.org/TR/CSS1/#url
|
||||
function escapePath(p: string) {
|
||||
return p.replace(/(\s|\(|\)|,|"|')/g, '\\$1');
|
||||
}
|
||||
|
||||
function resolveWorkspaceRoot(activeDoc: TextDocument, workspaceFolders: WorkspaceFolder[]): string | undefined {
|
||||
for (let i = 0; i < workspaceFolders.length; i++) {
|
||||
if (startsWith(activeDoc.uri, workspaceFolders[i].uri)) {
|
||||
|
||||
@@ -150,4 +150,16 @@ suite('Completions', () => {
|
||||
}, testUri, folders);
|
||||
});
|
||||
|
||||
test('CSS Path Completion - Proper escaping', function () {
|
||||
let testUri = Uri.file(path.resolve(__dirname, '../../test/pathCompletionFixtures/about/about.css')).toString();
|
||||
let folders = [{ name: 'x', uri: Uri.file(path.resolve(__dirname, '../../test')).toString() }];
|
||||
|
||||
assertCompletions('html { background-image: url(./|)', {
|
||||
items: [
|
||||
{ label: `about\\ \\(\\,\\'\\".css`, resultText: `html { background-image: url(./about\\ \\(\\,\\'\\".css)` }
|
||||
]
|
||||
}, testUri, folders);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user