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

Numeric text data is getting mangled #245

Closed
gharris999 opened this issue May 20, 2019 · 8 comments
Closed

Numeric text data is getting mangled #245

gharris999 opened this issue May 20, 2019 · 8 comments

Comments

@gharris999
Copy link

gharris999 commented May 20, 2019

Given:

#!/bin/bash
LDEV='wlx4cedfb37602e'
ESSID='SomeSSID'
WPA_PSK='123456789012'

yq n "network.wifis.${LDEV}.access-points.${ESSID}.password" "$WPA_PSK"

..yields:

network:
  wifis:
    wlx4cedfb37602e:
      access-points:
        SomeSSID:
          password: 1.23456789012e+11

..which won't do, of course. I need to store that wifi passkey string so that it can be interpreted literally. The interpreting program, netplan, isn't going to know that it needs to convert that scientific notation back into a string.

@gharris999
Copy link
Author

..this is with yq version 2.4.0

@gharris999
Copy link
Author

gharris999 commented May 20, 2019

So, I haven't looked at the source code yet, as I'm completely unfamiliar with Go, but looking at:

https://golang.org/pkg/fmt/

..I'm guessing that create/write/update actions add data using the %v format, which defaults to %g, which in turn defaults to %e for data interpreted as large exponents.

Perhaps yq could get an optional --fmt=%x flag argument for reads/writes that would allow run-time control over how data is interpreted and expressed. For my purposes, above, --fmt=%s would do nicely, e.g.:

yq n --fmt='%s' "network.wifis.${LDEV}.access-points.${ESSID}.password" "$WPA_PSK"

..to force $WPA_PSK to be interpreted as string data, not as a large number.

For more complicated string data, fmt even supports %q, "a double-quoted string safely escaped with Go syntax", which presumably would allow reading and writing virtually string data.

@gharris999
Copy link
Author

Actually,

yq n "network.wifis.${LDEV}.access-points.${ESSID}.password" "\"${WPA_PSK}\""

..yields:

network:
  wifis:
    wlx4cedfb37602e:
      access-points:
        SomeSSID:
          password: "123456789012"

..which netplan is OK with. So maybe this isn't the show-stopper issue I thought it was.

@AndiDog
Copy link

AndiDog commented May 22, 2019

Simpler test case:

$ echo 'version: 0.2' >Chart.yaml
$ yq w -i Chart.yaml version "0.10"
$ cat Chart.yaml
version: 0.1

So I had this nice one-liner to bump my helm chart version, and suddenly it jumps from 0.9 to 0.1...

@hobti01
Copy link
Contributor

hobti01 commented Aug 13, 2019

This is a sneaky one! It bit me today when a commit sha happened to have only numbers:

$ yq w -i helm/$NAME/values.yaml 'image.tag' $CI_COMMIT_SHORT_SHA
$ cat helm/$NAME/values.yaml
...
image:
  tag: 1.234556e+06
...

Thanks for the workaround @gharris999 !

@AdamSimpson
Copy link

I've been bit by this as well, a fix would be much appreciated.

larisau added a commit to larisau/yq that referenced this issue Nov 19, 2019
@mikefarah
Copy link
Owner

Just released a new version of yaml that fixes this - it's a pretty significant update so it's still in beta: https://github.com/mikefarah/yq/releases/tag/3.0.0-beta

@mikefarah
Copy link
Owner

Fixed in https://github.com/mikefarah/yq/releases/tag/3.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants