Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing Int32 despite non-int characters #145

Closed
Arokha opened this issue Oct 10, 2024 · 1 comment · Fixed by #146
Closed

Parsing Int32 despite non-int characters #145

Arokha opened this issue Oct 10, 2024 · 1 comment · Fixed by #146

Comments

@Arokha
Copy link

Arokha commented Oct 10, 2024

2018+ is parsed into an Int32, which seems unusual. I'd imagine at the very least that discarding a non-whitespace character from the yaml is a bug, instead of throwing on something that can't be unambiguously interpreted.

> ("2018+" | ConvertFrom-Yaml).GetType().Name
Int32

The YAML spec has some example schema (schemas? schemae??), all of which seem that they would interpret the above as a string instead of a number given the regex provided in-spec for integers: 0 | -? [1-9] [0-9]*

I tested two other popular parser implementations:
yaml (TypeScript), parses as string
pyyaml (Python), parses as string

Would this be something that could be altered? Or is this a YamlDotNet thing?

gabriel-samfira added a commit to gabriel-samfira/powershell-yaml that referenced this issue Oct 22, 2024
Using [Globalization.NumberStyles]::Any when parsing numbers will parse
even numbers that should be returned as strings, such as "2018+".

Explicitly using Integer and/or Float, will correclty parse integers and
scientific notation integers such as 1e+3.

Fixes: cloudbase#145

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
@gabriel-samfira
Copy link
Member

gabriel-samfira commented Oct 22, 2024

Hi @Arokha

Marrying C#/Powershell and Yaml is fun 🫠 .

Would you mind testing out #146 and see if that fixes the issue you're seeing?

P.S. Apologies for the late reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants