powershell.ps1: Validate Windows paths (#26488)

During the writing of Windows path integration tests we discovered that
incorrect paths (including escape sequences) cause very cryptic error
messages.

This fix ensures that invalid paths cause a proper error message.

We also had to fix the following modules:
- win_shortcut: `src` can be a URL
pull/26624/head
Dag Wieers 7 years ago committed by Matt Davis
parent c0fc79647a
commit 05e5698472

@ -205,6 +205,10 @@ Function Get-AnsibleParam($obj, $name, $default = $null, $resultobj = @{}, $fail
if ($type -eq "path") {
# Expand environment variables on path-type
$value = Expand-Environment($value)
# Test if a valid path is provided
if (-not (Test-Path -IsValid $value)) {
Fail-Json -obj $resultobj -message "Get-AnsibleParam: Parameter '$name' has an invalid path '$value' specified."
}
} elseif ($type -eq "str") {
# Convert str types to real Powershell strings
$value = $value.ToString()

@ -26,7 +26,7 @@ $ErrorActionPreference = "Stop"
$params = Parse-Args $args -supports_check_mode $true
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
$src = Get-AnsibleParam -obj $params -name "src" -type "path"
$src = Get-AnsibleParam -obj $params -name "src"
$dest = Get-AnsibleParam -obj $params -name "dest" -type "path" -failifempty $true
$state = Get-AnsibleParam -obj $params -name "state" -type "string" -default "present" -validateset "present","absent"
$orig_args = Get-AnsibleParam -obj $params -name "args" -type "string"

Loading…
Cancel
Save