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".