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

Fix int parsing for arg:"env" when environment variable value is empty #169

Closed

Conversation

rabingaire
Copy link

This PR fixes a bug in reference to #160

Copy link
Owner

@alexflint alexflint left a comment

Choose a reason for hiding this comment

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

Thank you for this PR, but I think there is some non-trivial subtlety to work out as per comments regarding *string

values, err = csv.NewReader(strings.NewReader(value)).Read()
value = strings.TrimSpace(value)

if len(value) > 0 {
Copy link
Owner

Choose a reason for hiding this comment

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

I think this will break the case that an argument type is *string and the env var is present but is empty, in which case the argument should be initialized to a non-null string, but its contents should be empty.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I missed this situation right now the argument is initialized null when this happens. I will work on this fix

@@ -677,6 +677,42 @@ func TestEnvironmentVariable(t *testing.T) {
assert.Equal(t, "bar", args.Foo)
}

func TestEnvironmentVariableInt(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

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

Would you add 3 extra test cases:

  • argument type is *string and environment variable is absent
  • argument type is *string and environment variable is present and empty
  • argument type is *string and environment variable is present and non-empty

Copy link
Author

Choose a reason for hiding this comment

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

I will add these test cases

@rabingaire rabingaire marked this pull request as draft November 10, 2021 16:36
when,
	argument type is *string and environment variable is absent
	argument type is *string and environment variable is present and empty
	argument type is *string and environment variable is present and non-empty
@rabingaire rabingaire closed this Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants