1
0
mirror of https://github.com/golang/go synced 2024-11-14 05:50:27 -07:00

strconv: quote rune 007F as \x7f, not \u007f

\u007f is not wrong but it's weird to use \u when we could use the
shorter \x.

Fixes #52062

Change-Id: Ica4bdc2463128051876f44e15297ed1e9edf1de8
Reviewed-on: https://go-review.googlesource.com/c/go/+/397255
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
Ian Lance Taylor 2022-03-31 12:30:14 -07:00
parent 825309962f
commit 31ee4bb28d
4 changed files with 14 additions and 3 deletions

View File

@ -371,7 +371,7 @@ pkg debug/elf, const ELFCLASSNONE = 0
pkg debug/elf, const ELFDATA2LSB = 1 pkg debug/elf, const ELFDATA2LSB = 1
pkg debug/elf, const ELFDATA2MSB = 2 pkg debug/elf, const ELFDATA2MSB = 2
pkg debug/elf, const ELFDATANONE = 0 pkg debug/elf, const ELFDATANONE = 0
pkg debug/elf, const ELFMAG = "\u007fELF" pkg debug/elf, const ELFMAG = "\x7fELF"
pkg debug/elf, const ELFOSABI_86OPEN = 5 pkg debug/elf, const ELFOSABI_86OPEN = 5
pkg debug/elf, const ELFOSABI_AIX = 7 pkg debug/elf, const ELFOSABI_AIX = 7
pkg debug/elf, const ELFOSABI_ARM = 97 pkg debug/elf, const ELFOSABI_ARM = 97

View File

@ -90,4 +90,14 @@ Do not send CLs removing the interior tags from such phrases.
issue tracker</a>. issue tracker</a>.
</p> </p>
</dd> </dd>
</dl> </dl><!-- net -->
<dl id="strconv"><dt><a href="/pkg/strconv/">strconv</a></dt>
<dd>
<p><!-- CL 397255 -->
<a href="/pkg/strconv/#strconv.Quote"><code>strconv.Quote</code></a>
and related functions now quote the rune 007F as <code>\x7f</code>,
not <code>\u007f</code>.
</p>
</dd>
</dl><!-- strconv -->

View File

@ -99,7 +99,7 @@ func appendEscapedRune(buf []byte, r rune, quote byte, ASCIIonly, graphicOnly bo
buf = append(buf, `\v`...) buf = append(buf, `\v`...)
default: default:
switch { switch {
case r < ' ': case r < ' ' || r == 0x7f:
buf = append(buf, `\x`...) buf = append(buf, `\x`...)
buf = append(buf, lowerhex[byte(r)>>4]) buf = append(buf, lowerhex[byte(r)>>4])
buf = append(buf, lowerhex[byte(r)&0xF]) buf = append(buf, lowerhex[byte(r)&0xF])

View File

@ -55,6 +55,7 @@ var quotetests = []quoteTest{
{"\x04", `"\x04"`, `"\x04"`, `"\x04"`}, {"\x04", `"\x04"`, `"\x04"`, `"\x04"`},
// Some non-printable but graphic runes. Final column is double-quoted. // Some non-printable but graphic runes. Final column is double-quoted.
{"!\u00a0!\u2000!\u3000!", `"!\u00a0!\u2000!\u3000!"`, `"!\u00a0!\u2000!\u3000!"`, "\"!\u00a0!\u2000!\u3000!\""}, {"!\u00a0!\u2000!\u3000!", `"!\u00a0!\u2000!\u3000!"`, `"!\u00a0!\u2000!\u3000!"`, "\"!\u00a0!\u2000!\u3000!\""},
{"\x7f", `"\x7f"`, `"\x7f"`, `"\x7f"`},
} }
func TestQuote(t *testing.T) { func TestQuote(t *testing.T) {