Skip to content

strings: TrimLeft fails in certain cases #61919

@sanketsudake

Description

@sanketsudake

What version of Go are you using (go version)?

$ go version
go version go1.20.7 darwin/amd64

Does this issue reproduce with the latest release?

Yes

https://go.dev/play/p/Abefs5j3At0

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

func main() {
	fmt.Println(strings.TrimLeft("user_support", "user_"))
	// Expected: support Actual: pport
	fmt.Println(strings.TrimLeft("user_conversation", "user_"))
	// Expected: conversation Actual: conversation
	fmt.Println(strings.TrimLeft("user_suconversation", "user_"))
	// Expected: suconversation Actual: conversation
}

https://go.dev/play/p/Abefs5j3At0

What did you expect to see?

TrimLeft output not expected in above cases. Output seems bit different when string contains su substring.

What did you see instead?

Please see above snippet.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions