Skip to content

Duplicate keys in spec #376

@straight-shoota

Description

@straight-shoota

When shard.yml contains duplicate keys for example two entries called dependencies, the spec parser concatenates the values:

yaml = <<-YAML
name: foo
version: 0.1.0

dependencies:
  foo:
    github: foo/foo
dependencies:
  bar:
    github: bar/bar
YAML
spec = Shards::Spec.from_yaml yaml

spec.dependencies.map(&.name) # => ["foo", "bar"]

This is unexpected and differes from any other YAML parser where previous values are simply overriden. For example YAML.parse behaves that way:

YAML.parse(yaml)["dependencies"].as_h.keys # => ["bar"]

As a result of this behaviour normalized YAML (for example passing yaml through YAML.parse(yaml).to_yaml parses differently than the ill-formed spec with duplicate keys.

I'd expect the parser to behave like other YAML parses and only use the last value. That's how it worked before #349. We could also consider to fails parsing such a a spec. Duplicate keys are clearly an error in the shard spec and should be fixed by the author. But issueing a warning is probably better.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions