Set-ModuleFunction errors when relative path is used
gaelcolas opened this issue · 4 comments
I've noticed that the Set-ModuleFunction throws an exception (can't find module) when a relative path to the PSD1 is used (instead of just the name).
This is because a new [PowerShell]
is used and no checks are done on Path/Name Parameter.
This could be checked with something like this after the Param block:
if($Name -match ([regex]::escape([io.path]::DirectorySeparatorChar)) -and ![io.path]::Isrooted($Name)) {
$Name = (Get-Item $Name).FullName
}
Or something like that (I haven't tested).
What about forcing a Resolve-Path
to clean it up a bit while achieving the same result? No need to really get the full item details if we're only looking to pull the full path (even though Get-Item
is speedy enough in most cases), Resolve-Path
would also handle the Directory Seperator.
Haven't had time to test, but something like the following on the function definition
$params = @{
Force = $True
Passthru = $True
Name = (Resolve-Path $Name)
}
Tested on my end and everything seems to be working well, getting a PR going soon
Closing this out, assuming it's up and running, feel free to re-open - thanks again @scrthq !