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 %% not working #25954

Closed
pjebs opened this issue Jun 19, 2018 · 12 comments
Closed

fmt %% not working #25954

pjebs opened this issue Jun 19, 2018 · 12 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@pjebs
Copy link
Contributor

pjebs commented Jun 19, 2018

This works on Go playground.

I have version: go version go1.10.1 darwin/amd64

box1 := "StandardHrs"
box2 := "0000-2400"
box3 := "100"

fmt.Println(fmt.Sprintf("[%s][%s][%s%%]", box1, box2, box3))

It should output:

[StandardHrs][0000-2400][100%]

It actually outputs:

[StandardHrs][0000-2400][100%!](MISSING)
@meirf
Copy link
Contributor

meirf commented Jun 19, 2018

Works for me on go1.10.3 darwin/amd64. Upgrade to latest?

@pjebs
Copy link
Contributor Author

pjebs commented Jun 19, 2018

I just downloaded the latest mac version on the official go website

@davecheney
Copy link
Contributor

Works for me as well. Please run this program to confirm you are using Go 1.10.1

package main

import (
        "fmt"
        "runtime"
)

func main() {
        fmt.Println(runtime.Version())
}

@davecheney davecheney added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 19, 2018
@pjebs
Copy link
Contributor Author

pjebs commented Jun 19, 2018

@davecheney go1.10.1

@pjebs
Copy link
Contributor Author

pjebs commented Jun 19, 2018

Double checked it and it definitely produces incorrect output.

@pjebs
Copy link
Contributor Author

pjebs commented Jun 19, 2018

I'm using mac 10.13.4

@davecheney
Copy link
Contributor

@pjebs can you please provide a runnable code sample, play.golang.org is the best, that shows the complete program. It doesn't have to fail in the playground, but it must be the same program that does fail on your laptop.

@meirf
Copy link
Contributor

meirf commented Jun 19, 2018

(I get the expected output both in 1.10.1 and 1.10.3, but on mac 10.13.3, which is different than the OP's. So maybe the difference is due to different OS version or we are not running the same code.)

@pjebs
Copy link
Contributor Author

pjebs commented Jun 19, 2018

When I make a standalone program that is simply:

package main

import (
	"fmt"
)

func main() {

	box1 := "StandardHrs"
	box2 := "0000-2400"
	box3 := "100"

	fmt.Println(fmt.Sprintf("[%s][%s][%s%%]", box1, box2, box3))
}

It works perfectly.

But in my code inside my function it doesn't work.

In fact even (inside my real-world code):

	a := "[StandardHrs][0000-2400][100%]"
	fmt.Println(len(a))
	fmt.Print(a)

outputs:

30
[StandardHrs][0000-2400][100%!](MISSING)

@agnivade
Copy link
Contributor

I am afraid you will have to debug this on your own. If the standalone example is not reproducible, it is very hard for us to debug anything.

Are you sure you are not redacting anything when pasting the code from the real world example ? Possibly, something in your code is adding an extra %.

@pjebs
Copy link
Contributor Author

pjebs commented Jun 19, 2018

I'll close it because I agree it's hard for you to help. But my code is not doing anything else. It's very simple.

@pjebs pjebs closed this as completed Jun 19, 2018
@pjebs
Copy link
Contributor Author

pjebs commented Jun 20, 2018

I can confirm the bug is related to using fresh to hot reload my application:
https://github.com/pilu/fresh

When I directly run my application uinsg go run *.go, it works fine.

@golang golang locked and limited conversation to collaborators Jun 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants