jm / toml

Parse TOML. Like a bawss.
MIT License
151 stars 37 forks source link

Fails on dots in hash keys #20

Open cbetta opened 11 years ago

cbetta commented 11 years ago

To replicate:

$ data = {"foo.bar" => "value" }
$ File.write('test.tml',  TOML::Generator.new(data).body)
$ TOML.load_file("test.tml")
Failed to match sequence (ALL_SPACE (KEY_GROUP / KEY_VALUE / COMMENT_LINE){0, } ALL_SPACE) at line 1 char 1.
`- Don't know what to do with "foo.bar = " at line 1 char 1.
NoMethodError: undefined method `each' for nil:NilClass
  from /Users/username/.rvm/gems/ruby-1.9.3-p448@gemset/gems/toml-0.0.4/lib/toml/parser.rb:21:in `initialize'
  from /Users/username/.rvm/gems/ruby-1.9.3-p448@gemset/gems/toml-0.0.4/lib/toml.rb:24:in `new'
  from /Users/username/.rvm/gems/ruby-1.9.3-p448@gemset/gems/toml-0.0.4/lib/toml.rb:24:in `load_file'
  from (irb):8
  from /Users/username/.rvm/rubies/ruby-1.9.3-p448/bin/irb:16:in `<main>'
parkr commented 11 years ago

Good catch. Is the following valid TOML?

foo.bar = "value"

From what I remember, TOML should prefer the following:

[foo]
bar = "value"
parkr commented 11 years ago

What output do you see in test.tml? (I think the correct extname is .toml btw, but that's neither here nor there in terms of this issue.)

cbetta commented 11 years ago

So it writes to the file:

foo.bar = "value"

Which I think isn't valid TOML.

Regardless, the problem seems to be that at the moment you can serialise something but then not read it back, which is pretty bad behaviour.

I suggest checking for valid keys.

biewers commented 5 years ago

I assume this defect is still open because dotted keys are indeed supported and the gem still does not support them? Is there any plan to add support for them? This issue is 6 years old now. Really just curious. Obvious workarounds exist.