Skip to content
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: exhibits strange behaviour when format strings contain spaces #17436

Closed
echlebek opened this issue Oct 13, 2016 · 1 comment
Closed

fmt: exhibits strange behaviour when format strings contain spaces #17436

echlebek opened this issue Oct 13, 2016 · 1 comment

Comments

@echlebek
Copy link

echlebek commented Oct 13, 2016

It seems that when spaces are inserted in a format string like %#v, some slightly surprising formatting occurs.

What version of Go are you using (go version)?

Go 1.7.1 (on the Go playground)

What operating system and processor architecture are you using (go env)?

The Go playground.

What did you do?

https://play.golang.org/p/2jeholpKdb

What did you expect to see?

I would expect to see errors from fmt complaining about invalid format strings, or a literal representation of the string without the formatting applied, or the space simply be ignored. Instead, the formatting is applied in an inconsistent way.

What did you see instead?

main.Compound{C:(*main.Compound)(0x1040e130), A:5, B:"foo"}
main.Compound{C:(*main.Compound)( 0x1040e130), A: 5, B:"foo"}
main.Compound{C:(*main.Compound)( 0x1040e130), A: 5, B:"foo"}
@mikioh mikioh changed the title fmt exhibits strange behaviour when format strings contain spaces fmt: exhibits strange behaviour when format strings contain spaces Oct 13, 2016
@ianlancetaylor
Copy link
Contributor

Note that space is a valid and documented flag character. The docs say leave a space for elided sign in numbers (% d); put spaces between bytes printing strings or slices in hex (% x, % X)".

I think the output shown above is correct, so I'm going to close this.

@golang golang locked and limited conversation to collaborators Oct 13, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants