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: Map does not process invalid UTF-8 sequences correctly #19330

Closed
martisch opened this issue Feb 28, 2017 · 1 comment
Closed

strings: Map does not process invalid UTF-8 sequences correctly #19330

martisch opened this issue Feb 28, 2017 · 1 comment
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@martisch
Copy link
Contributor

martisch commented Feb 28, 2017

go tip

The new strings.Map implementation introduced in http://golang.org/cl/33201/ does not correctly handle strings with invalid UTF-8 sequences.
This is due to a lack of differentiating between decoding an invalid sequence and the RuneError rune.

https://play.golang.org/p/A-UxFJNWAb

	replaceNotLatin := func(r rune) rune {
		if unicode.Is(unicode.Latin, r) {
			return r
		}
		return '?'
	}
	fmt.Println(strings.Map(replaceNotLatin, "Hello\255World"))

should print "Hello?World" but prints "Hello?rld".

@martisch martisch self-assigned this Feb 28, 2017
@martisch martisch added the NeedsFix The path to resolution is known, but the work has not been done. label Feb 28, 2017
@martisch martisch added this to the Go1.9 milestone Feb 28, 2017
@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Feb 28, 2018
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