From 98eee053c16a299b88a2ec28d61ad51696151dba Mon Sep 17 00:00:00 2001 From: Kirk Munro Date: Tue, 14 Mar 2017 14:43:56 -0300 Subject: [PATCH 1/2] Update PossibleIncorrectComparisonWithNull.md This is technically more accurate. PowerShell doesn't check for a $null in the array as was previously indicated. --- RuleDocumentation/PossibleIncorrectComparisonWithNull.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RuleDocumentation/PossibleIncorrectComparisonWithNull.md b/RuleDocumentation/PossibleIncorrectComparisonWithNull.md index 0df5404f9..a22309f43 100644 --- a/RuleDocumentation/PossibleIncorrectComparisonWithNull.md +++ b/RuleDocumentation/PossibleIncorrectComparisonWithNull.md @@ -7,7 +7,7 @@ To ensure that PowerShell performs comparisons correctly, the `$null` element should be on the left side of the operator. There are a number of reasons why this should occur: -* When there is an array on the left side of a null equality comparison, PowerShell will check for a `$null` IN the array rather than if the array is null. +* When there is an array on the left side of a null equality comparison, PowerShell will create a new array containing one `$null` item for each `$null` in the original array rather than check if the array is null. * PowerShell will perform type casting left to right, resulting in incorrect comparisons when `$null` is cast to other types. ## How From 400d965cd7090bc9e583996ef25013fc05b48f00 Mon Sep 17 00:00:00 2001 From: Kirk Munro Date: Fri, 29 Sep 2017 16:24:38 -0300 Subject: [PATCH 2/2] Update PossibleIncorrectComparisonWithNull.md Revised description based on comments. --- RuleDocumentation/PossibleIncorrectComparisonWithNull.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RuleDocumentation/PossibleIncorrectComparisonWithNull.md b/RuleDocumentation/PossibleIncorrectComparisonWithNull.md index a22309f43..15a11b1fd 100644 --- a/RuleDocumentation/PossibleIncorrectComparisonWithNull.md +++ b/RuleDocumentation/PossibleIncorrectComparisonWithNull.md @@ -7,8 +7,8 @@ To ensure that PowerShell performs comparisons correctly, the `$null` element should be on the left side of the operator. There are a number of reasons why this should occur: -* When there is an array on the left side of a null equality comparison, PowerShell will create a new array containing one `$null` item for each `$null` in the original array rather than check if the array is null. -* PowerShell will perform type casting left to right, resulting in incorrect comparisons when `$null` is cast to other types. +* `$null` is a scalar. When the input (left side) to an operator is a scalar value, comparison operators return a Boolean value. When the input is a collection of values, the comparison operators return any matching values, or an empty array if there are no matches in the collection. The only way to reliably check if a value is `$null` is to place `$null` on the left side of the operator so that a scalar comparison is perfomed. +* PowerShell will perform type casting left to right, resulting in incorrect comparisons when `$null` is cast to other scalar types. ## How