Skip to content

TOML decoding omits empty array inside table. #2674

@spohorecky-rai

Description

@spohorecky-rai

Describe the bug
Hi! Another rust user here, attempting to parse some Cargo.tomls. I have found that empty arrays (ex. my-feature = []) as required in the features table do not appear in the parsed output.

Thank you for the tool! 🙂

Version of yq: v4.52.5
Operating system: linux_amd64
Installed via: download via github release

Input TOML
Cargo.toml:

[package]
name = "my-package"
version = "0.1.0"
edition = "2024"
authors = ["me <me@me.com>"]

[dependencies]
zerocopy = "1.0.0"
serde = { workspace = true }

[features]
my-feature = []

Command
The command you ran:

yq '.' Cargo.toml

Actual behaviour

[package]
name = "my-package"
version = "0.1.0"
edition = "2024"
authors = ["me <me@me.com>"]

[dependencies]
zerocopy = "1.0.0"
serde = { workspace = true }

Expected behaviour

[package]
name = "my-package"
version = "0.1.0"
edition = "2024"
authors = ["me <me@me.com>"]

[dependencies]
zerocopy = "1.0.0"
serde = { workspace = true }

[features]
my-feature = []

Additional context

The whole features table disappears in the case where there are only features with empty arrays, but if you include a feature with a non-empty array, the table and the item appear, but not any items with empty arrays:

Example:

[package]
name = "my-package"
version = "0.1.0"
edition = "2024"
authors = ["me <me@me.com>"]

[dependencies]
zerocopy = "1.0.0"
serde = { workspace = true }

[features]
my-other-feature = []
my-feature = ["my-other-feature"]

Results:

> yq '.' example.toml -o toml
[package]
name = "my-package"
version = "0.1.0"
edition = "2024"
authors = ["me <me@me.com>"]

[dependencies]
zerocopy = "1.0.0"
serde = { workspace = true }

[features]
my-feature = ["my-other-feature"]

I did also confirm that empty arrays at top-level are parsed, so seems to be specific to empty arrays within tables.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions