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

Unsafe characters in command names breaks markdown file creation on Windows #602

Closed
3 tasks done
ShaunLawrie opened this issue Jun 17, 2023 · 2 comments
Closed
3 tasks done
Labels
Resolution-Answered The question is answered.

Comments

@ShaunLawrie
Copy link

ShaunLawrie commented Jun 17, 2023

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.

Steps to reproduce

Creating markdown help for commands that have unsafe characters in their name causes the file creation to fail on Windows.
I ran into this trying to generate help docs for PowerShellAI because it uses some unusual command names that contain question marks in them.

Expected behavior

PS> New-MarkdownHelp -Module "PowerShellAI"

# Markdown is created for all exported functions and aliases

Actual behavior

PS5> New-MarkdownHelp -Module "PowerShellAI"

# Most functions are exported to markdown then the file creation fails for "gh?"

PSCore> New-MarkdownHelp -Module "PowerShellAI"

# Most functions are exported to markdown then the file creation fails for "gh?"

Error details

Set-Content : An object at the specified path psaihelp4\gh?.md does not exist, or has been filtered by the -Include or -Exclude parameter.
At C:\Users\shaun.lawrie\Documents\WindowsPowerShell\Modules\platyPS\0.14.2\platyPS.psm1:1956 char:5
+     Set-Content -Path $Path -Value ''
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (System.String[]:String[]) [Set-Content], Exception
    + FullyQualifiedErrorId : ItemNotFound,Microsoft.PowerShell.Commands.SetContentCommand
    
Exception calling "WriteAllText" with "3" argument(s): "Empty path name is not legal."
At C:\Users\shaun.lawrie\Documents\WindowsPowerShell\Modules\platyPS\0.14.2\platyPS.psm1:1958 char:5
+     [System.IO.File]::WriteAllText($resolvedPath, $value, $Encoding)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentException

Environment data

PS> Get-Module platyPS -ListAvailable

    Directory: C:\Users\shaun.lawrie\Documents\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.14.2     platyPS                             {New-MarkdownHelp, Get-MarkdownMetadata, New-ExternalHelp, New-YamlHelp...}

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.22000.1335
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22000.1335
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

# This also fails in PowerShell core 7

Name                           Value
----                           -----
PSVersion                      7.3.4
PSEdition                      Core
GitCommitId                    7.3.4
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image

image

@ShaunLawrie ShaunLawrie added the Needs-Triage The issue is new and needs to be triaged by a work group. label Jun 17, 2023
@sdwheeler
Copy link
Collaborator

I am not sure what the impact of unsafe characters would be on Get-Help and Update-Help. The filename wouldn't match the true command name. This is a pattern that we would never support internally.

I am not sure we should try to support this for external customers.

@sdwheeler sdwheeler added Review-Needed The PR is being reviewed and removed Needs-Triage The issue is new and needs to be triaged by a work group. labels Nov 2, 2023
@sdwheeler
Copy link
Collaborator

@sdwheeler sdwheeler added Resolution-Answered The question is answered. and removed Review-Needed The PR is being reviewed labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-Answered The question is answered.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants