mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
strings: fix encoding of \u0080 in map
Fix encoding of PAD (U+0080) which has the same value as utf8.RuneSelf being incorrectly encoded as \x80 in strings.Map due to using <= instead of a < comparison operator to check one byte encodings for utf8. Fixes #25242 Change-Id: Ib6c7d1f425a7ba81e431b6d64009e713d94ea3bc Reviewed-on: https://go-review.googlesource.com/111286 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
98409a44d5
commit
8c62fc0ca3
2 changed files with 25 additions and 2 deletions
|
|
@ -479,7 +479,7 @@ func Map(mapping func(rune) rune, s string) string {
|
|||
b = make([]byte, len(s)+utf8.UTFMax)
|
||||
nbytes = copy(b, s[:i])
|
||||
if r >= 0 {
|
||||
if r <= utf8.RuneSelf {
|
||||
if r < utf8.RuneSelf {
|
||||
b[nbytes] = byte(r)
|
||||
nbytes++
|
||||
} else {
|
||||
|
|
@ -509,7 +509,7 @@ func Map(mapping func(rune) rune, s string) string {
|
|||
r := mapping(c)
|
||||
|
||||
// common case
|
||||
if (0 <= r && r <= utf8.RuneSelf) && nbytes < len(b) {
|
||||
if (0 <= r && r < utf8.RuneSelf) && nbytes < len(b) {
|
||||
b[nbytes] = byte(r)
|
||||
nbytes++
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue