Skip to content

Read-Host -Prompt accidentally exposes prompt commands meant for prompting for mandatory parameters only #4066

@mklement0

Description

@mklement0

Note: This problem has been known for a long time - for background, see this SO answer.

Read-Host -Prompt - at least in the regular console host and in the ISE in PSv3+ - accidentally exposes functionality that only makes sense in the context of prompting a user for missing mandatory parameter values, namely, the so-called prompt commands that start with !.

Note:

  • Happens only when the -Prompt parameter is used.

  • The ISE in PSv3 through PSv5.1 accepts ! as a literal !, but the console host complains about an invalid prompt command (see below); even the ISE, however, interprets !? as a prompt command, for instance. (Note that the ISE in v2- used its own, GUI prompt for Read-Host, and was therefore not affected.)

Steps to reproduce

Run in a console window / terminal.

> Read-Host -Prompt 'hi'
hi: !  # The "!" is entered by the user.


> Read-Host -Prompt 'hi'
hi: !? # The "!?" is entered by the user.

Expected behavior

!
!?

That is, whatever the user entered should be output as-is, with no interpretation whatsoever.

Actual behavior

"!" cannot be recognized as a valid Prompt command.
No help is available for hi.

That is,

  • ! was interpreted as the start of a prompt command.

  • !? was interpreted as the command to print the "parameter's" help message, which, of course, only makes sense in the context of prompting for mandatory parameter values.

Environment data

PowerShell Core v6.0.0-beta (v6.0.0-beta.2) on macOS 10.12.5
PowerShell Core v6.0.0-beta (v6.0.0-beta.2) on Ubuntu 16.04.1 LTS
PowerShell Core v6.0.0-beta (v6.0.0-beta.2) on Microsoft Windows 10 Pro (64-bit; v10.0.14393)
Windows PowerShell v5.1.15063.413 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)

Metadata

Metadata

Assignees

Labels

Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions