-
Notifications
You must be signed in to change notification settings - Fork 33.3k
fix escaping for terminal completions for zsh/bash/fish #251989
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
base: main
Are you sure you want to change the base?
Conversation
Working on pwsh now |
Just realized maybe we want to handle escaping where this gets inserted instead of changing the label? Yes, going with that instead |
pwsh seems involved, skipping for now |
src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalCompletionService.ts
Outdated
Show resolved
Hide resolved
src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalCompletionEscapeHelper.ts
Outdated
Show resolved
Hide resolved
6d9c5e5
to
6cd435c
Compare
src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalCompletionService.ts
Outdated
Show resolved
Hide resolved
I manually tested each to make sure it's necessary @Tyriar and added tests too. |
@Tyriar could you pls review? |
export function escapeTerminalCompletionLabel(label: string, shellType: TerminalShellType, pathSeparator: string): string { | ||
// Only escape for bash/zsh/fish; PowerShell and cmd have different rules | ||
if (shellType === GeneralShellType.PowerShell || shellType === WindowsShellType.CommandPrompt) { | ||
// TODO: Implement escaping for PowerShell/cmd if needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove unless it's needed?
const specialCharsSet = new Set(['[', ']', '(', ')', '\'', '"', '\\', '`', '*', '?', ';', '&', '|', '<', '>']); | ||
const specialCharsRegex = /[\[\]\(\)'"\\\`\*\?;|&<>]/; | ||
if (!specialCharsRegex.test(label)) { | ||
return label; | ||
} | ||
return label.split('').map(c => specialCharsSet.has(c) ? '\\' + c : c).join(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (shellType) { | ||
label = escapeTerminalCompletionLabel(label, shellType, resourceRequestConfig.pathSeparator); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Could move the if into the escape function and allow it to accept shellType undefined to simplify this function a little
fixes #249024