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

parse does not properly handle floats of the form ".8" #144

Closed
ycz opened this issue Mar 20, 2020 · 5 comments
Closed

parse does not properly handle floats of the form ".8" #144

ycz opened this issue Mar 20, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@ycz
Copy link

ycz commented Mar 20, 2020

> yaml.parse('foo: .8')
{ foo: '.8' }

Here, the value of foo should be the number 0.8 instead of the string '.8'.

The 1.1 schema does work properly:

> yaml.parse('foo: .8', { schema: 'yaml-1.1' })
{ foo: 0.8 }
@ycz ycz changed the title parse does not properly handle floats of the form .8 parse does not properly handle floats of the form ".8" Mar 20, 2020
@eemeli
Copy link
Owner

eemeli commented Mar 21, 2020

Huh. You're right. I'm truly rather surprised that this hasn't been noticed before. Will fix ASAP.

Also, the trickier problem that this has surfaced for me is that I notice that the official YAML 1.1 !!float RegExp (which we use) is buggy, as it'll catch a solitary . as a "valid" float value:

> YAML.parse('.', { version: '1.1' })
NaN

To be clear, that's entirely separate from this issue, but now I'm conflicted about what the right thing might be, to follow the spec (as we currently do), or "fix" the expression. :/

@eemeli eemeli added the bug Something isn't working label Mar 21, 2020
@eemeli eemeli closed this as completed in 61b45d4 Mar 21, 2020
@jtbandes
Copy link

This regexp is a bit strange IMO: (?:\.([0-9]+)|(?:0|[1-9][0-9]*)\.([0-9]*)) — is "00.1" not supposed to be a valid float?

@eemeli
Copy link
Owner

eemeli commented Mar 21, 2020

🤦‍♂️Yes, it is.

@eemeli eemeli reopened this Mar 21, 2020
@eemeli eemeli closed this as completed in 3a23187 Mar 21, 2020
@eemeli
Copy link
Owner

eemeli commented Mar 21, 2020

Thank you @ycz and @jtbandes for pointing these out. It's been a while since someone discovered something so deeply wrong with this library.

@jtbandes
Copy link

Thanks for the quick responses!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants