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
This commit is contained in:
Dag Wieers 2017-07-10 19:45:16 +02:00 committed by Matt Davis
parent c0fc79647a
commit 05e5698472
2 changed files with 5 additions and 1 deletions

View file

@ -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()