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

provisioner: update split template function logic for empty input #658

Merged
merged 1 commit into from
Mar 29, 2023

Conversation

AlexanderYastrebov
Copy link
Member

Splitting empty string intuitively should produce zero parts.

Stdlib strings.Split returns s if s does not contain d therefore strings.Split("", ",") returns one part [""].

This should simplify a common pattern:

{{ if ne .ConfigItems.foo "" }}
{{ range $bar := split .ConfigItems.foo "," }}
  - "{{ $bar }}"
{{ end }}
{{ end }}

to

{{ range $bar := split .ConfigItems.foo "," }}
  - "{{ $bar }}"
{{ end }}

"foo,bar")

require.NoError(t, err)
require.Equal(t, "0=foo1=bar", result)
Copy link
Member

Choose a reason for hiding this comment

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

minor: "0=foo1=bar" this format seems very strange to me. However, I think it already works here, so see no problem merging it.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not a format really but a test template to show what are the values it ranges over

@RomanZavodskikh
Copy link
Member

👍

Splitting empty string intuitively should produce zero parts.

Stdlib strings.Split returns s if s does not contain d therefore
strings.Split("", ",") returns one part [""].

This should simplify a common pattern:
```
{{ if ne .ConfigItems.foo "" }}
{{ range $bar := split .ConfigItems.foo "," }}
  - "{{ $bar }}"
{{ end }}
{{ end }}
```
to
```
{{ range $bar := split .ConfigItems.foo "," }}
  - "{{ $bar }}"
{{ end }}
```

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
@mikkeloscar
Copy link
Contributor

👍

1 similar comment
@AlexanderYastrebov
Copy link
Member Author

👍

@AlexanderYastrebov AlexanderYastrebov merged commit 6943896 into master Mar 29, 2023
@AlexanderYastrebov AlexanderYastrebov deleted the provisioner/split-empty branch March 29, 2023 13:59
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.

None yet

3 participants