diff --git a/src/extension/executors/runner/index.ts b/src/extension/executors/runner/index.ts index f2949d962..2dad9469d 100644 --- a/src/extension/executors/runner/index.ts +++ b/src/extension/executors/runner/index.ts @@ -33,7 +33,12 @@ import { RunProgramOptions, } from '../../runner' import { IRunnerEnvironment } from '../../runner/environment' -import { getAnnotations, getCellRunmeId, getTerminalByCell } from '../../utils' +import { + getAnnotations, + getCellRunmeId, + getTerminalByCell, + unescapeShellLiteral, +} from '../../utils' import { postClientMessage } from '../../../utils/messaging' import { getCloseTerminalOnSuccess, @@ -609,9 +614,11 @@ export async function promptVariablesAsync( case UNRESOLVED_WITH_PLACEHOLDER: case UNRESOLVED_WITH_SECRET: { const key = variable.name - const placeHolder = variable.resolvedValue || variable.originalValue || 'Enter a value please' const hasStringValue = variable.status === UNRESOLVED_WITH_PLACEHOLDER const isPassword = variable.status === UNRESOLVED_WITH_SECRET + const placeHolder = unescapeShellLiteral( + variable.resolvedValue || variable.originalValue || 'Enter a value please', + ) const userInput = await promptUserForVariable(key, placeHolder, hasStringValue, isPassword) diff --git a/src/extension/utils.ts b/src/extension/utils.ts index 9055b4fb4..5c02c3ca9 100644 --- a/src/extension/utils.ts +++ b/src/extension/utils.ts @@ -243,6 +243,16 @@ export function normalizeLanguage(l?: string) { } } +export function unescapeShellLiteral(escaped: string) { + return escaped + .replace(/\\\(/g, '(') + .replace(/\\\)/g, ')') + .replace(/\\\{/g, '{') + .replace(/\\\}/g, '}') + .replace(/\\\[/g, '[') + .replace(/\\\]/g, ']') +} + export async function verifyCheckedInFile(filePath: string) { const fileDir = path.dirname(filePath) const workspaceFolder = vscode.workspace.workspaceFolders?.find((ws) => diff --git a/tests/extension/utils.test.ts b/tests/extension/utils.test.ts index 9eb896b65..fb0d1337f 100644 --- a/tests/extension/utils.test.ts +++ b/tests/extension/utils.test.ts @@ -29,6 +29,7 @@ import { asWorkspaceRelativePath, editJsonc, getGitContext, + unescapeShellLiteral, } from '../../src/extension/utils' import { ENV_STORE, DEFAULT_ENV } from '../../src/extension/constants' import { CellAnnotations } from '../../src/types' @@ -251,6 +252,19 @@ test('getKeyInfo', () => { }) }) +test('unescapeShellLiteral', () => { + expect(unescapeShellLiteral('echo "Hello World!"')).toBe('echo "Hello World!"') + expect(unescapeShellLiteral('echo "Hello ${name}!"')).toBe('echo "Hello ${name}!"') + expect(unescapeShellLiteral('[Guest type \\(hyperv,proxmox,openstack\\)]')).toBe( + '[Guest type (hyperv,proxmox,openstack)]', + ) + expect(unescapeShellLiteral('[IP of waiting server \\{foo\\}]')).toBe( + '[IP of waiting server {foo}]', + ) + expect(unescapeShellLiteral('[Guest\\ Type]')).toBe('[Guest\\ Type]') + expect(unescapeShellLiteral('\\[Guest Type\\]')).toBe('[Guest Type]') +}) + suite('normalizeLanguage', () => { test('with zsh', () => { const lang = normalizeLanguage('zsh')