dasel icon indicating copy to clipboard operation
dasel copied to clipboard

Parser drops everything after empty yaml doc

Open Cenness opened this issue 10 months ago • 1 comments

Discussion? No

Describe the bug On multidoc yaml input dasel drops all elements after first empty doc.

To Reproduce

  1. Create yaml
first: nonempty
---

---
second: nonempty
---

  1. Run cat md.yaml | dasel -r yaml -w yaml
  2. Get
first: nonempty

Expected behavior

$ cat md.yaml | yq
first: nonempty
---

---
second: nonempty
---

Screenshots N/A

Desktop:

  • OS: Debian 12
  • Version: dasel version v2.8.1

Additional context

  • yq is mikefarah/yq
  • Multidoc yaml with empty docs in the middle can be seen in the wild on helm charts when entire template file is skipped due to some condition.
  • cat md.yaml | yq -o json | dasel -r json -w yaml crashes into panic, which is preferable to silently skipping payload
  • v3 panics with runtime error: invalid memory address or nil pointer dereference

Cenness avatar Apr 10 '25 09:04 Cenness

This happens for multiple root elements in XML too, I think?

at 13:41:17 ❯ cat index.html | htmlq "h1,h2,h3,h4,h5,h6"
<h2>About</h2>
<h2>Projects</h2>
<h3>Web badges <small><a href="https://en.wikipedia.org/wiki/Web_badge">Explain?</a></small></h3>
<h4>Sources, where known:</h4>
at 13:41:54 ❯ cat index.html | htmlq "h1,h2,h3,h4,h5,h6" | dasel -r xml
<h2>About</h2>

It only ever references the first "root".

kittywitch avatar Nov 27 '25 21:11 kittywitch

Hi there,

Thanks for your patience.

I've fixed the issue with V3:

echo 'first: nonempty                                              
---

---
second: nonempty
---' | dasel -i yaml
first: nonempty
---
second: nonempty

I opted to ignore completely empty documents, however I may change this if there are enough requests for that empty document to come through.

TomWright avatar Dec 10 '25 17:12 TomWright

@kittywitch Thanks for raising the point on XML reading issues.

In V3 (active development, hopefully released fully soon) you can query the XML and it seems to work:

echo '<h2>About</h2>
<h2>Projects</h2>
<h3>Web badges <small><a href="https://en.wikipedia.org/wiki/Web_badge">Explain?</a></small></h3>
<h4>Sources, where known:</h4>' | go run cmd/dasel/main.go -i xml -o json --read-flag xml-mode=structured 'children'
[
    {
        "name": "h2",
        "attrs": {},
        "content": "About",
        "children": []
    },
    {
        "name": "h2",
        "attrs": {},
        "content": "Projects",
        "children": []
    },
    {
        "name": "h3",
        "attrs": {},
        "content": "Web badges ",
        "children": [
            {
                "name": "small",
                "attrs": {},
                "content": "",
                "children": [
                    {
                        "name": "a",
                        "attrs": {
                            "href": "https://en.wikipedia.org/wiki/Web_badge"
                        },
                        "content": "Explain?",
                        "children": []
                    }
                ]
            }
        ]
    },
    {
        "name": "h4",
        "attrs": {},
        "content": "Sources, where known:",
        "children": []
    }
]

If you could raise a separate issue with your expected input/output I'll see what I can do to support your needs.

TomWright avatar Dec 10 '25 17:12 TomWright

V3 has been released so I think this is fixed. Please let me know if I'm wrong.

TomWright avatar Dec 15 '25 13:12 TomWright