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

TOML nested array of tables with arrays breaks v4.35.1 #1758

Open
mbigras opened this issue Aug 19, 2023 · 2 comments
Open

TOML nested array of tables with arrays breaks v4.35.1 #1758

mbigras opened this issue Aug 19, 2023 · 2 comments
Labels

Comments

@mbigras
Copy link

mbigras commented Aug 19, 2023

Describe the bug

Hi! First of all, thank you so much for making and maintaining yq; I happily use your tool everyday and especially thank you for starting work on TOML support—see #1364 issue!

Issue: I noticed that yq breaks when parsing TOML nested array of tables with arrays (lol)—see Array of Tables section. Workaround: To work around, you can parse TOML with tomljson command, then pipe JSON to yq.

Version of yq: v4.35.1,...,v4.42.1
Operating system: Mac and Linux
Installed via: Homebrew and Docker

Input TOML
data1.toml:

[[fruits]]
name = "apple"
[[fruits.varieties]]  # nested array of tables
name = "red delicious"

Command
The command you ran:

yq -ptoml -oyaml data1.toml

Actual behavior

Error: bad file 'data1.toml': cannot index array with 'varieties' (strconv.ParseInt: parsing "varieties": invalid syntax)

Expected behavior

fruits:
  - name: apple
    varieties:
      - name: red delicious

Additional context
I suspect this is a problem with yq because the tomljson command can handle data1.toml like the following shell session illustrates:

$ tomljson /dev/stdin <<'TOML' | yq -P
[[fruits]]
name = "apple"
[[fruits.varieties]]  # nested array of tables
name = "red delicious"
TOML
fruits:
  - name: apple
    varieties:
      - name: red delicious

Again, thank you for yq and please advise if I should do any other experiments.

@edmorley
Copy link

edmorley commented Sep 25, 2023

We're encountering this too, in:
https://github.com/heroku/builder/actions/runs/6303904793/job/17114118993?pr=392#step:5:9

When running yq '.stack.run-image' builder-22/builder.toml against this toml file:
https://github.com/heroku/builder/blob/b83a3606a68b882484ee3353a58c2813d321a9f4/builder-22/builder.toml

@antoinedeschenes
Copy link

Also seeing the issue with sub-tables, for example:

curl -s https://raw.githubusercontent.com/veertuinc/gitlab-runner/master/config.toml.example | yq -p toml -o yaml .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants