Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Asymmetry between CSV serialization of properties with AutomationNull or $null values #24699

Copy link
Copy link
@surfingoldelephant

Description

@surfingoldelephant
Issue body actions

Prerequisites

There is asymmetry between the serialization of properties with either AutomationNull ([Management.Automation.Internal.AutomationNull]::Value) or $null values, that affects the following formats:

  • CSV
  • CLIXML
  • XML

This issue focuses on CSV. I will address (CLI)XML in a separate issue as the behavior differs.

Consider the following contrived example:

[pscustomobject] @{
    Prop = if ($false) { 'Foo' } else { $null }
} | ConvertTo-Csv

# "Prop"

[pscustomobject] @{
    # Statement assignments have pipeline semantics, so Prop receives AutomationNull.
    Prop = if ($false) { 'Foo' }
} | ConvertTo-Csv

# "Prop"
# ""

A typical PS user who is unaware of AutomationNull (and arguably should not have to be) would reasonably expect equivalent CSV serialization. Yet, the result differs because AutomationNull as a property value serializes as a quoted ("") empty field whereas $null serializes as unquoted.

Notes:

Steps to reproduce

[pscustomobject] @{ P1 = & {}; P2 = $null } | ConvertTo-Csv

Expected behavior

CSV serialization of AutomationNull and $null property values should be identical.

The result should be either:

# "P1","P2"
# "",""

# Or...

# "P1","P2"
# ,

Depending on whether AutomationNull/$null should both be a quoted or unquoted empty field. Note that this has deserialization implications, as noted in the aforementioned #17702 issue.

Actual behavior

Serialization of AutomationNull and $null property values differs.

  • AutomationNull: "" (quoted)
  • $null: Nothing (unquoted)
"P1","P2"
"",

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.0-rc.1
PSEdition                      Core
GitCommitId                    7.5.0-rc.1
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-DeclinedThe proposed feature is declined.The proposed feature is declined.WG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.