Parser drops everything after empty yaml doc
Discussion? No
Describe the bug On multidoc yaml input dasel drops all elements after first empty doc.
To Reproduce
- Create yaml
first: nonempty
---
---
second: nonempty
---
- Run
cat md.yaml | dasel -r yaml -w yaml - 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 yamlcrashes into panic, which is preferable to silently skipping payload - v3 panics with
runtime error: invalid memory address or nil pointer dereference
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".
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.
@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.
V3 has been released so I think this is fixed. Please let me know if I'm wrong.