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

Can't parse Float64 starting with zero on YAML files? #5698

Closed
ghost opened this issue Feb 9, 2018 · 4 comments
Closed

Can't parse Float64 starting with zero on YAML files? #5698

ghost opened this issue Feb 9, 2018 · 4 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib

Comments

@ghost
Copy link

ghost commented Feb 9, 2018

Crystal version:

Crystal 0.24.1 (2017-12-26) LLVM: 5.0.1 Default target: x86_64-apple-macosx

This works:

require "yaml"

class Config
  YAML.mapping(x: Int32, y: Float64)
end

str = <<-YAML
dev:
  x: 12464  
  y: 3.5
YAML
 
dev = Hash(String, Config).from_yaml(str)["dev"]
dev.y  # => 3.5

This doesn't:

require "yaml"

class Config
  YAML.mapping(x: Int32, y: Float64)
end

str = <<-YAML
dev:
  x: 12464  
  y: 0.5
YAML
 
dev = Hash(String, Config).from_yaml(str)["dev"] 
#=> Expected Float64, not 0.5 at line 3, column 6

I'm using scientific notation (5e-2) as a workaround at the moment, which also works.

@straight-shoota
Copy link
Member

Seems like the yaml core parser treats any plain value starting with a zero as an octal integer.

@ghost
Copy link
Author

ghost commented Feb 9, 2018

Yeah... .5 also doesn't work

@straight-shoota
Copy link
Member

But that's according to the spec http://yaml.org/type/float.html

@straight-shoota
Copy link
Member

straight-shoota commented Feb 9, 2018

I have a patch for this issue but discovered some other issues with parsing YAML floats in the process :/

@asterite asterite added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib labels Feb 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib
Projects
None yet
Development

No branches or pull requests

2 participants