Fix a possible issue with comparing values with $null (#37763)

This PR includes:
- Fix $null comparison.
- Simplify Get-AnsibleParam in the same effort
pull/48860/head
Dag Wieers 6 years ago committed by Jordan Borean
parent f69e3e1cec
commit 5f6a350b3a

@ -201,11 +201,12 @@ Function Get-AnsibleParam($obj, $name, $default = $null, $resultobj = @{}, $fail
}
}
# If $value -eq $null, the parameter was unspecified by the user (deliberately or not)
# If $null -eq $value, the parameter was unspecified by the user (deliberately or not)
# Please leave $null-values intact, modules need to know if a parameter was specified
# When $value is already an array, we cannot rely on the null check, as an empty list
# is seen as null in the check below
if ($null -ne $value -or $value -is [array]) {
if ($null -eq $value) {
return $null
}
if ($type -eq "path") {
# Expand environment variables on path-type
$value = Expand-Environment($value)
@ -249,7 +250,6 @@ Function Get-AnsibleParam($obj, $name, $default = $null, $resultobj = @{}, $fail
# , is not a typo, forces it to return as a list when it is empty or only has 1 entry
return ,$value
}
}
return $value
}

Loading…
Cancel
Save