Skip to content

Incorrectly read the version number #152

@xrgzs

Description

@xrgzs

I try to read a YAML configuration file that defines a version number, and I'm getting unexpected results.

Simplified as follows:

PS D:\> "version: 3.10" | ConvertFrom-Yaml

Name                           Value
----                           -----
version                        3.1

PS D:\> ("version: 3.10" | ConvertFrom-Yaml).version
3.1

The type is System.Double. This makes my script recognize the wrong version number.

PS D:\> ('version: 3.10' | convertFrom-Yaml).version.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Double                                   System.ValueType

Then I try to convert a JSON string of the same data. It returns different results from ConvertFrom-Json.

PS D:\> '{"version": 3.10}' | ConvertFrom-Yaml

Name                           Value
----                           -----
version                        3.1

PS D:\> '{"version": 3.10}' | ConvertFrom-Json

version
-------
   3.10

This is my environment:

PS D:\> Get-Module -Name powershell-yaml

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     0.4.7                 powershell-yaml                     {ConvertFrom-Yaml, ConvertTo-Yaml, cfy, cty}

PS D:\> $PSVersionTable

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

I think it would be better to provide an swich to treat number as string.

Or can someone give me a solution? I don't want to use regex.😭

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions