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

Empty string becoming null when modifying YAML #400

Open
blurayne opened this issue Mar 22, 2024 · 4 comments
Open

Empty string becoming null when modifying YAML #400

blurayne opened this issue Mar 22, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@blurayne
Copy link

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 blurayne added the bug Something isn't working label Mar 22, 2024
@blurayne
Copy link
Author

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

@TomWright
Copy link
Owner

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

@blurayne
Copy link
Author

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.

@TomWright
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants