jm / toml

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

Error while parsing valid toml #66

Open schneems opened 3 years ago

schneems commented 3 years ago

Reproduction:

cd /tmp
cat > foo.toml <<EOF
api = "0.4"

[buildpack]
id = "heroku/java-function"
version = "0.3.21"
name = "Java Function"
homepage = "https://github.com/heroku/buildpacks-jvm"
keywords = ["java", "function"]

[[licenses]]
type = "MIT"

[[order]]

[[order.group]]
id = "heroku/jvm"
version = "0.1.8"

[[order.group]]
id = "heroku/maven"
version = "0.2.5"

[[order.group]]
id = "heroku/jvm-function-invoker"
version = "0.5.3"

[metadata]

[metadata.release]

[metadata.release.docker]
repository = "public.ecr.aws/heroku-buildpacks/heroku-java-function-buildpack"
EOF

gem install toml
ruby -rtoml -e "TOML.load(File.read('foo.toml'))"

Expected: Toml to be parsed Actual:

/Users/rschneeman/.gem/ruby/3.0.2/gems/toml-0.3.0/lib/toml/parser.rb:57:in `resolve_table_array': undefined method `has_key?' for nil:NilClass (NoMethodError)
    from /Users/rschneeman/.gem/ruby/3.0.2/gems/toml-0.3.0/lib/toml/parser.rb:37:in `block in initialize'
    from /Users/rschneeman/.gem/ruby/3.0.2/gems/toml-0.3.0/lib/toml/parser.rb:16:in `each'
    from /Users/rschneeman/.gem/ruby/3.0.2/gems/toml-0.3.0/lib/toml/parser.rb:16:in `initialize'
    from /Users/rschneeman/.gem/ruby/3.0.2/gems/toml-0.3.0/lib/toml.rb:19:in `new'
    from /Users/rschneeman/.gem/ruby/3.0.2/gems/toml-0.3.0/lib/toml.rb:19:in `load'
    from -e:1:in `<main>'

Ruby: 3.0.2 I checked the toml on disk is valid with https://www.toml-lint.com/

janie314 commented 1 year ago

Yes, I couldn't get it to parse the following Cargo.toml which works fine with Rust's cargo.

[package]
name = "test"
version = "0.4.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.2.7", features = ["derive"] }
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.93"
ureq = { version = "2.7.0", features = ["json"] }

This parsed it fine, however. https://github.com/emancu/toml-rb