Empty string becoming null when modifying YAML
I use dasel in a helm filter to modify template for k8s.
Unfortunately modifying YAML ends in empty string becoming null.
How to reproduce
foo.yaml:
kind: ConfigMap
data:
foo: hello
script:
namespace: myworld
---
kind: xvdcscd
data:
foo: bar
Now modify:
cat foo.yaml | dasel put -t string -v "bar" -r yaml -h 'all().filter(equal(kind,ConfigMap)).data.foo'
Now watch the value for key script
kind: ConfigMap
data:
foo: bar
script: null
---
kind: xvdcscd
data:
foo: bar
Version
Tested on Linux AMD64, dasel version v2.7.0
I just downloaded that release after I encountered the bug with an older release (some weeks old).
What else?
If this is standard behavior it would be nyce to add a command-line flag to change this. Dasel is far easier to use then kustomize. Also tools like jq/yq/oq don't help since they cannot parse manifests divided by '---'.
Workaround
For the moment I added an additonal pipe with:
dasel put -t string -v "" -r yaml -w yaml 'all().filter(equal(kind,ConfigMap)).data.all().filter(equal(.,null))'
But workarounds are not a solution since they don't solve the original problem but cure the effect ;)
Hey @blurayne, my guess this is how the yaml parser is interpreting the value.
Does it help if you change the original file to be value: ""?
Nope. In the original I had
key: |
with just a newline. Reading via dasel -r yaml -w plain gave BOM plus newline. So I guess it happens somewhere between.
Thanks for the info. I'll do some digging when I get a chance