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 · 5 comments
Open

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

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

Comments

@mbigras
Copy link

mbigras commented Aug 19, 2023

Describe the bug

Hi! Thank you for making and maintaining yq; I happily use your tool daily and especially thanks for starting work on TOML support—see #1364!

Issue: Yq breaks when parsing TOML nested array of tables with arrays (LOL)—see https://toml.io/en/v1.0.0#array-of-tables. Workaround: You can parse TOML with https://github.com/pelletier/go-toml, 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 can handle data1.toml like the following shell session illustrates:

$ tomljson /dev/stdin <<'TOML' | yq -pjson -oyaml
[[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 for considering this sort of obtuse issue.

@edmorley
Copy link

edmorley commented Sep 25, 2023

@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 .

@vindex10
Copy link

still relevant.

Thank you for supporting TOML!

@kleinschmidt
Copy link

Another potentially useful test case:

julia_version = "1.10.5"
manifest_format = "2.0"
project_hash = "6a7f2fbcfb1740b9273397ba607e5438aaea4fa8"

[[deps.AbstractFFTs]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "d92ad398961a3ed262d8bf04a1a2b8340f915fef"
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
version = "1.5.0"
weakdeps = ["ChainRulesCore", "Test"]

    [deps.AbstractFFTs.extensions]
    AbstractFFTsChainRulesCoreExt = "ChainRulesCore"
    AbstractFFTsTestExt = "Test"

(this is from a Julia language Manifest.toml file which I was hoping to use yq to pull some metadata from)

@kleinschmidt
Copy link

Huh, it's interesting that tomljson works w/ this syntax but yq doesn't, they're both using the same library under the hood (https://github.com/mikefarah/yq/blob/master/pkg/yqlib/decoder_toml.go#L13)

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

5 participants