Skip to content
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

Read-Host: Show how to trim leading and trailing whitespace from user input #10088

Closed
3 tasks done
mklement0 opened this issue May 22, 2023 · 4 comments · Fixed by #10089
Closed
3 tasks done

Read-Host: Show how to trim leading and trailing whitespace from user input #10088

mklement0 opened this issue May 22, 2023 · 4 comments · Fixed by #10089
Labels
area-conceptual Area - Conceptual articles issue-doc-bug Issue - error in documentation

Comments

@mklement0
Copy link
Contributor

Prerequisites

  • Existing Issue: Search the existing issues for this repository. If there is an issue that fits your needs do not file a new one. Subscribe, react, or comment on that issue instead.
  • Descriptive Title: Write the title for this issue as a short synopsis. If possible, provide context. For example, "Typo in Get-Foo cmdlet" instead of "Typo."
  • Verify Version: If there is a mismatch between documentation and the behavior on your system, ensure that the version you are using is the same as the documentation. Check this box if they match or the issue you are reporting is not version specific.

Links

https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Read-Host?view=powershell-7.3&viewFallbackFrom=powershell-7

Summary

Typically, any leading or trailing whitespace in user input is considered incidental, and the desire is to remove it.

As an aside: The following feature request asks for a -Trim switch to support incidental whitespace removal directly.

In the absence of direct trimming support in Read-Host (at least for now), showing an example of how to trim after the fact would be helpful; e.g.:

$userInput = (Read-Host 'Enter something').Trim()

Details

No response

Suggested Fix

No response

@mklement0 mklement0 added issue-doc-bug Issue - error in documentation needs-triage Waiting - Needs triage labels May 22, 2023
@sdwheeler
Copy link
Contributor

I don't think this belongs in the Read-Host docs for the same reasons cited in PowerShell/PowerShell#19680 (comment). However, I think a conceptual article that covered string manipulation would be useful and more appropriate.

@sdwheeler sdwheeler added area-conceptual Area - Conceptual articles and removed needs-triage Waiting - Needs triage labels May 22, 2023
@mklement0
Copy link
Contributor Author

@sdwheeler, I find the reasoning in the linked comment specious, and I will respond in detail there.

In summary, let me say: Read-Host and Write-Host are essential for building user interfaces, which has nothing to do with the automatic prompting mechanism for mandatory parameters (which is so limited as to be near useless - see PowerShell/PowerShell#4068 and PowerShell/PowerShell#7093)

As noted, wanting to remove incidental whitespace is the typical use case.

That Read-Host doesn't even support that on an opt-in basis is unfortunate, so the next best thing is to show how to do it manually, which is therefore very much appropriate for the Read-Host help topic (and is not mutually exclusive with a general string-handling conceptual topic).

michaeltlombardi added a commit to michaeltlombardi/PowerShell-Docs that referenced this issue May 22, 2023
Prior to this change, the documentation for the `Read-Host` cmdlet didn't include
information about trimming the input. The cmdlet doesn't have a built-in way to
trim extra spaces from the input value, which is an arbitrary string.

This change:

- Adds an example to `Read-Host` showing how user input may need to normalized
  before it can be used. It also shows how a reader can apply some simple
  normalizing techniques to clean up the input.
- Resolves MicrosoftDocs#10088
- Fixes AB#91532
michaeltlombardi added a commit to michaeltlombardi/PowerShell-Docs that referenced this issue May 22, 2023
Prior to this change, the documentation for the `Read-Host` cmdlet didn't include
information about trimming the input. The cmdlet doesn't have a built-in way to
trim extra spaces from the input value, which is an arbitrary string.

This change:

- Adds an example to `Read-Host` showing how user input may need to normalized
  before it can be used. It also shows how a reader can apply some simple
  normalizing techniques to clean up the input.
- Resolves MicrosoftDocs#10088
- Fixes AB#91532
sdwheeler pushed a commit that referenced this issue May 22, 2023
Prior to this change, the documentation for the `Read-Host` cmdlet didn't include
information about trimming the input. The cmdlet doesn't have a built-in way to
trim extra spaces from the input value, which is an arbitrary string.

This change:

- Adds an example to `Read-Host` showing how user input may need to normalized
  before it can be used. It also shows how a reader can apply some simple
  normalizing techniques to clean up the input.
- Resolves #10088
- Fixes AB#91532
@sdwheeler
Copy link
Contributor

Reopening this issue. We still should create an article about string manipulation.

@sdwheeler
Copy link
Contributor

Created #10289 to track new article

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-conceptual Area - Conceptual articles issue-doc-bug Issue - error in documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants