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

*Slice: don't mutate the underlying default value #1170

Merged
merged 1 commit into from Aug 26, 2020

Conversation

@tych0
Copy link

@tych0 tych0 commented Aug 5, 2020

*Slice: don't mutate the underlying default value

If the default value is present, we shouldn't mutate it. Appending slices
as the code was before mutates the underlying value:

package main

import (
        "fmt"
)

func main() {
        slice := []string{"a", "b", "c"}

        fmt.Println(append(slice[:1], slice[2:]...))
        fmt.Println(slice)
}
~ go run tester2.go
[a c]
[a c c]

Let's fix this by creating and returning an entirely new slice.

Closes #1169

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
If the default value is present, we shouldn't mutate it. Appending slices
as the code was before mutates the underlying value:

package main

import (
	"fmt"
)

func main() {
	slice := []string{"a", "b", "c"}

	fmt.Println(append(slice[:1], slice[2:]...))
	fmt.Println(slice)
}
~ go run tester2.go
[a c]
[a c c]

Let's fix this by creating and returning an entirely new slice.

Closes #1169

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
@tych0 tych0 requested a review from urfave/cli as a code owner Aug 5, 2020
@tych0 tych0 requested review from saschagrunert and asahasrabuddhe Aug 5, 2020
@tych0
Copy link
Author

@tych0 tych0 commented Aug 20, 2020

Ping?

Copy link
Member

@saschagrunert saschagrunert left a comment

LGTM

@rliebz
rliebz approved these changes Aug 26, 2020
@rliebz rliebz merged commit af7fa3d into urfave:v1 Aug 26, 2020
8 checks passed
8 checks passed
ubuntu-latest @ Go 1.11 ubuntu-latest @ Go 1.11
Details
ubuntu-latest @ Go 1.12 ubuntu-latest @ Go 1.12
Details
ubuntu-latest @ Go 1.13 ubuntu-latest @ Go 1.13
Details
macos-latest @ Go 1.11 macos-latest @ Go 1.11
Details
macos-latest @ Go 1.12 macos-latest @ Go 1.12
Details
macos-latest @ Go 1.13 macos-latest @ Go 1.13
Details
codecov/patch 85.29% of diff hit (target 71.70%)
Details
codecov/project 72.68% (+0.98%) compared to 1b32836
Details
tych0 added a commit to anuvu/stacker that referenced this pull request Sep 28, 2020
urfave/cli#1170 was merged, so let's move to that
commit upstream.

Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants