-
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: "%%" placeholder accepts incorrect index values #22868
Comments
Since documentation says "%% a literal percent sign; consumes no value" the index for the non consumed value is not checked. This could be explicity documented or easily changed by changing the order in which this switch statement in fmt is evaluated: Line 1084 in 2e1f071
However changing this is a backwards incompatible change that can break code (even if unlikely case) that worked fine before. |
Speaking about 'consumes no value'.
So if we use index for width or precision, value is consumed and still index is not checked. |
Your examples all look like they are behaving correctly to me. One could argue that [100] should give an error, but since it fetches no argument it's also fine to say it's a no-op. |
And what about indices for width and precision? Value is consumed, so this is not a no-op. I found another interesting case connected to width and precision:
So if width/precision index is correct, %% behaves like any other verb and consumes corresponding value. If index is incorrect (not a number, < 1, or > arguments number), it consumes the first value. |
OK, that does look like a bug, although it's hard to get excited about it. |
What version of Go are you using (go version)?
go1.9.2
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env)?
macOS Sierra 10.12.6, darwin/amd64
What did you do?
Run the following code
What did you expect to see?
In all cases, errors about incorrect index is printed.
What did you see instead?
In all cases, '%' is printed. This behaviour is unexpected and, at least, not documented here:
https://golang.org/pkg/fmt/
The text was updated successfully, but these errors were encountered: