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

strings: regression in Trim functionality #17611

Closed
dsnet opened this issue Oct 26, 2016 · 1 comment
Closed

strings: regression in Trim functionality #17611

dsnet opened this issue Oct 26, 2016 · 1 comment
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dsnet
Copy link
Member

dsnet commented Oct 26, 2016

8737dac caused a regression where the functionality of Trim changed with an invalid cutset.

Consider the following test:

func Test(t *testing.T) {
    s1 := strings.Trim("\x80test\xff", "\xff")
    s2 := bytes.Trim([]byte("\x80test\xff"), "\xff")
    if s1 != string(s2) {
        t.Errorf("Trim() = %q, want %q", s1, s2)
    }
}

On Go 1.7, this passes with s1==s2=="test"
On tip, this fails with s1=="\x80test\xff" and s2=="test"

The string passed into the cutset is an invalid UTF-8 string, but I have actually seen a few instances of this in production code (filed a lint check for this: golang/lint#252). Regardless, the behavior of this edge case should be preserved from Go 1.7 to Go 1.8.

\cc @bradfitz @hirochachacha

@dsnet dsnet added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 26, 2016
@dsnet dsnet added this to the Go1.8 milestone Oct 26, 2016
@dsnet dsnet self-assigned this Oct 26, 2016
@gopherbot
Copy link

CL https://golang.org/cl/32123 mentions this issue.

@golang golang locked and limited conversation to collaborators Oct 26, 2017
@rsc rsc unassigned dsnet Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants