Skip to content

Using [System.String]::Join($null, ...) joins with \0 rather than a truly null value. #25351

@mjr4077au

Description

@mjr4077au

Prerequisites

Steps to reproduce

I tried finding an existing open/closed issue for this but could not. I'm not even sure if it's a PowerShell thing or a .NET thing.

In Windows PowerShell 5.1, a setup like [System.String]::Join($null, (1,2,3)).Length returns 3, however in PowerShell 7.4.7, this returns 5. If I change out the $null for an empty string, I get the expected length of 3.

Expected behavior

PS D:\Repos\PSAppDeployToolkit\src> [System.String]::Join($null, (1,2,3)).Length
3

Actual behavior

PS C:\Users\mjr40> [System.String]::Join($null, (1,2,3)).Length
5

Error details

Notes on the issue can be read in PSAppDeployToolkit issue PSAppDeployToolkit/PSAppDeployToolkit#1413.

Environment data

PS C:\Users\mjr40> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.7
PSEdition                      Core
GitCommitId                    7.4.7
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

PowerShell 7.4.7:
Image

Windows PowerShell 5.1:
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-Won't FixThe issue won't be fixed, possibly due to compatibility reason.WG-Enginecore PowerShell engine, interpreter, and runtimeWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions