Skip to content

Converting a hashtable to [pscustomobject] unexpectedly stringifies keys in a culture-sensitive fashion #14278

@mklement0

Description

@mklement0

Note: This isn't likely to arise often in practice, but is an inconsistency that should be addressed.

In most contexts, notably in string interpolation, PowerShell uses the invariant rather than the current culture for converting numbers to strings, for consistency across cultures; e.g., "$(1.2)" yields '1.2' in any culture, i.e. . is always used as the decimal mark.

By contrast, when hash tables are converted to [pscustomobject]s, which necessitates converting non-string keys to strings, keys that are either of type [double] or [decimal] are unexpectedly stringified based on the current culture.

Steps to reproduce

try {
 $org = [cultureinfo]::CurrentCulture
 [cultureinfo]::CurrentCulture = 'fr-FR'  # e.g.; use a culture that uses "," as the decimal mark
 ([pscustomobject] @{ 1.2 = 'hi' }).'1.2' | Should -Be 'hi'
} finally {
 [cultureinfo]::CurrentCulture = $org
}

Expected behavior

The test should succeed, because [double] 1.2 should always stringify to '1.2'.

Actual behavior

The test fails, because with culture fr-FR (French) in effect, where , is the decimal mark, 1.2 stringified to '1,2'.

Expected 'hi', but got $null.

Environment data

PowerShell Core 7.2.0-preview.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking-Changebreaking change that may affect usersIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-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