Skip to content

fix(pkg/strvals): preserve leading zeros in vals - #2729

Merged
thomastaylor312 merged 2 commits into
helm:masterfrom
rbwsam:fix/leading_zeros
Aug 8, 2017
Merged

thomastaylor312 merged 2 commits into
helm:masterfrom
rbwsam:fix/leading_zeros

Conversation

@rbwsam

@rbwsam rbwsam commented Jul 27, 2017

Copy link
Copy Markdown
Contributor

When passing values with "helm install --set" values with leading zeros are
preserved and not parsed as ints.

Closes #2693

When passing values with "helm install --set" values with leading zeros are
preserved and not parsed as ints.

Closes #2693
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 27, 2017
Comment thread pkg/strvals/parser.go Outdated
if iv, err := strconv.ParseInt(val, 10, 64); err == nil {
return iv
// If this value does not start with zero, try parsing it to an int
if len(val) != 0 && val[0] != 48 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity/lack of understanding, what does 48 translate to in this situation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

48 is the ASCII value for 0. Thanks for pointing this out, this prompted me to learn more about runes and I found out that a better implementation would be to use a rune literal '0' instead which better communicates the intent of the code.

When checking that a value begins with zero use a rune literal instead of the
ASCII code for zero.

@thomastaylor312 thomastaylor312 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this and it looks good to go

@thomastaylor312 thomastaylor312 added this to the 2.6.0 - Features milestone Aug 8, 2017
@thomastaylor312
thomastaylor312 merged commit 8eaed9d into helm:master Aug 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants