Commit 221af5c1 authored by Rob Pike's avatar Rob Pike

fmt: treat \r\n as \n in Scan

When scanning input and "white space" is permitted, a carriage return
followed immediately by a newline (\r\n) is treated exactly the same
as a plain newline (\n). I hope this makes it work better on Windows.

We do it everywhere, not just on Windows, since why not?

Fixes #5391.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12142043
parent a696ae56
......@@ -215,6 +215,10 @@
stops if it does not, with the return value of the function
indicating the number of arguments scanned.
In all the scanning functions, a carriage return followed
immediately by a newline is treated as a plain newline
(\r\n means the same as \n).
In all the scanning functions, if an operand implements method
Scan (that is, it implements the Scanner interface) that
method will be used to scan the text for that operand. Also,
......
......@@ -437,6 +437,9 @@ func (s *ss) skipSpace(stopAtNewline bool) {
if r == eof {
return
}
if r == '\r' && s.peek("\n") {
continue
}
if r == '\n' {
if stopAtNewline {
break
......
......@@ -192,6 +192,10 @@ var scanTests = []ScanTest{
{"-.45e1-1e2i\n", &complex128Val, complex128(-.45e1 - 100i)},
{"hello\n", &stringVal, "hello"},
// Carriage-return followed by newline. (We treat \r\n as \n always.)
{"hello\r\n", &stringVal, "hello"},
{"27\r\n", &uint8Val, uint8(27)},
// Renamed types
{"true\n", &renamedBoolVal, renamedBool(true)},
{"F\n", &renamedBoolVal, renamedBool(false)},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment