From 8c62fc0ca3c96ecbd3a6e81546aa8c53e32ff500 Mon Sep 17 00:00:00 2001 From: Martin Möhrmann Date: Fri, 4 May 2018 06:54:18 +0200 Subject: strings: fix encoding of \u0080 in map MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/strings/strings.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/strings/strings.go') diff --git a/src/strings/strings.go b/src/strings/strings.go index 45345e0088..adbbe742fc 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -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 -- cgit v1.3-5-g45d5