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

1

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

Merodach answered 9/7, 2014 at 19:6 Comment(2)
It seems revel is broken and is using Printf...Beebread
This did not even occur to me. Wow. I'm sitting here reinstalling everything and feeling pretty stupid. :-PMerodach
W
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.)

Wanderoo answered 9/7, 2014 at 19:51 Comment(2)
Yeah--it sounds more like revel.INFO.Println is like Printf.Provocative
Right, sorry. I'll fix the answer. Thanks!Wanderoo

© 2022 - 2024 — McMap. All rights reserved.