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

Permit --var values to contain newlines. #580

Merged
merged 2 commits into from
Dec 3, 2021
Merged

Conversation

ragaskar
Copy link
Contributor

@ragaskar ragaskar commented Dec 2, 2021

  • yaml.Unmarshall mangles newlines in non-yaml partials. This commit
    checks the return value type and, if string (what appears to be
    returned by yaml.Unmarshal for invalid YAML input), simply passes
    through the original string value.
  • Although this is a behavior change, it is not expected that any
    user would be depending on this behavior.

[#180138088]

Signed-off-by: Rajan Agaskar ragaskar@vmware.com

- yaml.Unmarshall mangles newlines in non-yaml partials. This commit
  checks the return value type and, if string (what appears to be
  returned by yaml.Unmarshal for invalid YAML input), simply passes
  through the original string value.
- Although this is a behavior change, it is not expected that any
  user would be depending on this behavior.

[#180138088]

Signed-off-by: Rajan Agaskar <ragaskar@vmware.com>
@@ -33,7 +33,11 @@ func (a *VarKV) UnmarshalFlag(data string) error {
return bosherr.WrapErrorf(err, "Deserializing variables '%s'", data)
}

*a = VarKV{Name: pieces[0], Value: vars}
if _, ok := vars.(string); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty bad at Go, but this is weird enough that it should have a comment explaining what it's doing and why it's doing it. I can guess, but I definitely wouldn't be confident in my guess without a lot of research.

Copy link
Member

Choose a reason for hiding this comment

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

I think the technical term for this is a type assertion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, the commit message serves as an explanation, but a comment can be added as a convenience.

Copy link
Contributor

@klakin-pivotal klakin-pivotal Dec 2, 2021

Choose a reason for hiding this comment

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

This must be a lie, right?

> If i does not hold a T, the statement will trigger a panic.

Nevermind, I'm an idiot that hasn't had coffee yet... that's when you use the variant that doesn't return an error status.

@@ -56,5 +56,13 @@ var _ = Describe("VarKV", func() {
Expect(val3).To(Equal(map[interface{}]interface{}{"key31": "str"}))
})
})

Context("When key/value has newlines", func() {
Copy link
Member

Choose a reason for hiding this comment

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

Might as well specify in the context that the string is not a yaml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

- Eliminates the need for future developers to do git archaeology.

Signed-off-by: Rajan Agaskar <ragaskar@vmware.com>
@rkoster rkoster requested review from a team, jpalermo and beyhan and removed request for a team December 3, 2021 15:31
Copy link
Contributor

@rkoster rkoster left a comment

Choose a reason for hiding this comment

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

LTGM

@rkoster
Copy link
Contributor

rkoster commented Dec 3, 2021

Enough people have looked at this, gonna merge, Thanks @ragaskar

@rkoster rkoster merged commit 0aa6596 into main Dec 3, 2021
@rkoster rkoster deleted the allow_newlines_in_var branch December 3, 2021 18:34
@beyhan
Copy link
Member

beyhan commented Dec 8, 2021

I somehow missed that I was assigned as reviewer to this pr. I have created a small refactoring suggestion in #581. @selzoc and @klakin-pivotal as you have been involved in the discussion here could you provide your feedback for #581.

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

Successfully merging this pull request may close these issues.

7 participants