Skip to content

[S.M.A.Internal.AutomationNull]::Value is treated like a collection when used with -match, -notmatch, -like, -notlike #3866

Description

@KirkMunro

Steps to reproduce

Set-Content -Value $null -Path .\zero.txt -NoNewline -Encoding Ascii
(get-item .\zero.txt).Length -eq 0 # returns $true
$content = gc .\zero.txt -Raw -Encoding Ascii
$content -eq $null # returns $true
$null -eq $content # returns $true
$content -match 'anything' # returns nothing, but should return $false
[System.Management.Automation.Internal.AutomationNull]::Value -match 'anything' # ditto
$null -match 'anything' # returns $false

Expected behavior

$true
$true
$true
$false
$false
$false

Actual behavior

$true
$true
$true
# returns nothing at all
# returns nothing at all
$false

Impact

This makes it more difficult to write scripts that process content in files, because tests that should fail return nothing instead, so if you were checking for a failure and then jumping to the next iteration of the loop with continue, your continue does not get called and then unpredictable things can happen as a result.

Environment data

Reproduced in PowerShell 5.1 and 6.0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions