Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 8, 2026

The script required users to manually double-escape backslashes in UNC paths (e.g., \\\\localhost\\share instead of \\localhost\share). This was error-prone and the help text explaining this was only visible on request. Additionally, usernames (especially domain accounts like DOMAIN\user) and passwords could contain backslashes and special characters that weren't being escaped.

Changes

  • cf-create-service.ps1: Uses PowerShell's built-in ConvertTo-Json for automatic JSON escaping

    • Accepts natural UNC paths, usernames, and passwords from users
    • Automatically escapes all special characters (backslashes, quotes, etc.) in all three parameters
    • Added #Requires -Version 7.0 directive to ensure PowerShell 7+ compatibility
    • Updated parameter help text to reflect simplified usage
    • Single conversion method - no duplicate escape logic
  • README.md: Updated documentation to show natural parameter format

    • Added note about PowerShell 7+ requirement
    • Documented domain username support (e.g., DOMAIN\username)

Example

Before:

.\cf-create-service.ps1 -NetworkAddress "\\\\myserver\\myshare" -UserName "user" -Password "pass"

After:

# Works with domain usernames and special characters in passwords
.\cf-create-service.ps1 -NetworkAddress "\\myserver\myshare" -UserName "DOMAIN\user" -Password 'p@ss"word'

The script now uses ConvertTo-Json to produce properly-escaped JSON for all parameters, handling backslashes, quotes, and other special characters automatically while accepting intuitive input.

Original prompt

This section details on the original issue you should resolve

<issue_title>Parameter escaping in cf-create-service.ps1</issue_title>
<issue_description>The parameters need to be passed to the cf cli as json, which can be tricky to escape correctly. Currently, the user is expected to do the escaping ("For example, if the path is '\localhost\steeltoe_network_share', use '\\localhost\steeltoe_network_share'"), but the help text must be specficially requested by typing !? in order to show up.

Can the script handle the escaping internally so the script is easier to use?</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix parameter escaping in cf-create-service.ps1 Handle UNC path escaping internally in cf-create-service.ps1 Jan 8, 2026
Copilot AI requested a review from TimHess January 8, 2026 20:14
@TimHess
Copy link
Member

TimHess commented Jan 8, 2026

@copilot, the username will also commonly have a backslash as well, and I suppose there's no guarantee a password wouldn't either. Add the escaping to those two params as well. Also evaluate whether additional characters could break this script, like single or double-quotes - can those be handled as well? Assuming there are additional characters that need to be escaped, consider using a built-in powershell function (it would be acceptable to also adjust the script to require pwsh 7+ to minimize compatibility concerns) or refactoring to avoid duplicating the escape logic

Copy link
Contributor Author

Copilot AI commented Jan 8, 2026

@copilot, the username will also commonly have a backslash as well, and I suppose there's no guarantee a password wouldn't either. Add the escaping to those two params as well. Also evaluate whether a...

Done in commit f10b9b5. The script now uses PowerShell's ConvertTo-Json function which automatically handles escaping for all parameters (NetworkAddress, UserName, and Password). This properly escapes:

  • Backslashes in UNC paths, usernames (DOMAIN\user), and passwords
  • Double quotes and other special characters

Added #Requires -Version 7.0 directive and updated README.md to document the PowerShell 7+ requirement and domain username support.

Copilot AI changed the title Handle UNC path escaping internally in cf-create-service.ps1 Handle parameter escaping internally in cf-create-service.ps1 Jan 8, 2026
@TimHess TimHess marked this pull request as ready for review January 8, 2026 20:51
@TimHess TimHess requested review from bart-vmware and Copilot January 8, 2026 20:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the usability of the cf-create-service.ps1 script by handling JSON parameter escaping internally instead of requiring users to manually escape special characters. The script now uses PowerShell's ConvertTo-Json cmdlet to automatically handle escaping of backslashes, quotes, and other special characters in UNC paths, usernames (including domain accounts), and passwords.

Key changes:

  • Replaced manual string formatting with ConvertTo-Json for automatic JSON escaping
  • Updated help text and documentation to reflect simplified usage with natural input formats
  • Added PowerShell 7.0+ requirement directive

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
FileShares/scripts/cf-create-service.ps1 Implements automatic JSON escaping using ConvertTo-Json, updates parameter help text, and adds PowerShell 7.0 version requirement
FileShares/README.md Updates documentation to show natural UNC path format, adds PowerShell 7+ requirement note, and documents domain username support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@TimHess TimHess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, here's the result of a test run:

PS C:\source\steeltoe-samples\FileShares\scripts> .\cf-create-service.ps1

cmdlet cf-create-service.ps1 at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
NetworkAddress: \\myserver\myshare
UserName: mydomain\useraccount
Password: some\ridulous"'passw\o/rd"""''"""''"''\'"
cf create-service credhub default sampleNetworkShare -c {"location":"\\\\myserver\\myshare","password":"some\\ridulous\"'passw\\o/rd\"\"\"''\"\"\"''\"''\\'\"","username":"mydomain\\useraccount"} -t sampleNetworkShare
Creating service instance sampleNetworkShare in org / space as <user>...

Service instance sampleNetworkShare created.
OK

@TimHess TimHess force-pushed the copilot/handle-parameter-escaping branch from 5f1b634 to 5b9701c Compare January 13, 2026 18:59
Copilot AI and others added 4 commits January 13, 2026 15:48
Co-authored-by: TimHess <3947063+TimHess@users.noreply.github.com>
Co-authored-by: TimHess <3947063+TimHess@users.noreply.github.com>
Co-authored-by: TimHess <3947063+TimHess@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@TimHess TimHess force-pushed the copilot/handle-parameter-escaping branch from 5b9701c to 88fc5c6 Compare January 13, 2026 21:49
@@ -1,15 +1,28 @@
#Requires -Version 7.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this? The script is only useful on Windows, so it would be nice if users could run it with the built-in Windows PowerShell instead of installing PowerShell Core first.

$ParamJSON = [string]::Format('{{\"location\":\"{0}\",\"username\":\"{1}\",\"password\":\"{2}\"}}', $NetworkAddress, $UserName, $Password)
# Build parameter object and convert to JSON using PowerShell's built-in JSON serialization
# This automatically handles escaping of special characters including backslashes, quotes, etc.
$params = @{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable names are very inconsistent. Some are camelCase, others are PascalCase (all should be the former). The names range from $redactedParams (plural; the type of params before it) to $ParamJSON (singular, the type after it) and $ParamJSONRedacted (singular, the type before and after it).

Suggested:
$params (array)
$jsonParams (string)
$redactedParams (array)
$redactedJsonParams (string)

* `-NetworkAddress \\\\<hostname>\\<sharename>` - escaped UNC path of the fileshare
* `-UserName <username>` - the username for accessing the fileshare
* `-NetworkAddress \\<hostname>\<sharename>` - UNC path of the fileshare
* `-UserName <username>` - the username for accessing the fileshare (can include domain, e.g., `DOMAIN\username`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explanations here and in the script itself should be synced up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parameter escaping in cf-create-service.ps1

3 participants