Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL Escaping producing "%A(MISSING)" instead of "%3A"

Tags:

url

go

revel

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

like image 958
Bjorn Roche Avatar asked Jul 09 '14 19:07

Bjorn Roche


1 Answers

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.)

like image 58
Daniel Darabos Avatar answered Nov 10 '22 18:11

Daniel Darabos