dasel icon indicating copy to clipboard operation
dasel copied to clipboard

Empty string becoming null when modifying YAML

Open blurayne opened this issue 1 year ago • 4 comments

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

blurayne avatar Mar 22 '24 11:03 blurayne

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 ;)

blurayne avatar Mar 22 '24 11:03 blurayne

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: ""?

TomWright avatar Mar 22 '24 18:03 TomWright

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.

blurayne avatar Mar 22 '24 20:03 blurayne

Thanks for the info. I'll do some digging when I get a chance

TomWright avatar Mar 22 '24 22:03 TomWright