-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fmt: inconsistent handling of \r in Scanf #9459
Comments
Same behaviour with go version go1.2.1 linux/amd64 on Ubuntu 14.04. |
Same behavior on go1.4 windows/amd64 |
As I understand, you have to give the \n in the format string if a newline is expected. Then it will work regardless of the line ending. From the fmt package documentation: Scanf, Fscanf and Sscanf require newlines in the input to match newlines in the format However, I think the documentation is misleading: 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). Always, and then there is a bug, or only when the formatting string has a \n? |
Working as intended, but the documentation needs to be improved. |
There have been several fixes to fmt.Scanf in the recent flurry. Your example behaves consistently for me now if I rewrite it as follows, making sure the newlines appear in the format to match the input.
|
In go1.5 the Scanf parser was changed WRT to line feeds. Newer versions of go would fail on every fmt.Sscanf function due to: golang/go#9459
I got different
fmt.Scanf
behavior depending on the line endings style.My go version is go1.3.3 darwin/amd64 on a Mac with OSX 10.10
To reproduce the problem, here is a short go program:
And an input file
go run test.go < input
I expect to see regardless of the line endings been
\r\n
or\n
:But I see
when in the input file the line endings are
\r\n
.If the line endings are
\n
it works fine.The text was updated successfully, but these errors were encountered: