10

I am using the revel framework with the go language. Recently, when I run the following code:

import (
    ...
    "net/url"
    ...
)

revel.INFO.Println(url.QueryEscape("http://hello.com"))

I get

INFO  2014/07/09 14:58:34 user.go:39: http%A(MISSING)%F(MISSING)%F(MISSING)hello.com

When I expect to get something more like

INFO  2014/07/09 14:58:34 user.go:39: http%3A%2F%2Fhello.com

Why has %3A been replaced by %A(MISSING) in the output and how can I fix it?

The only go code where I see something that might produce the string "(MISSING)' is in the fmt package, but from looking at the net/url source code package, I don't see how that could be happening. Am I perhaps somehow accessing an old (and broken?) version of the go libraries? Is something else possibly wrong with my setup?

Related: Encode / decode URLs

Relevant Go Source code: http://golang.org/src/pkg/net/url/url.go?s=14330:14361#L553

Community
  • 1
  • 1
Bjorn Roche
  • 11,279
  • 6
  • 36
  • 58

1 Answers1

7

revel.INFO.Println is like fmt.Printf, it expects a format string and arguments. To log a string that contains % characters you either need to escape it, or better pass it as an argument:

revel.INFO.Println("The escaped URL is: %s", url.QueryEscape("http://hello.com"))

(You could just use "%s" as the format string, but why not take the chance to provide context.)

Daniel Darabos
  • 26,991
  • 10
  • 102
  • 114