http.URLEscape not escaping $

24 views
Skip to first unread message

Roger Pau Monné

unread,
Sep 3, 2010, 1:01:22 PM9/3/10
to golang-nuts
Hello,

I've just noticed that URLEscape in the http package doesn't escape
"$" properly, it should be encoded as "%24", is this normal?
Now I'm using this expression to overcome the problem:

strings.Replace(http.URLEscape(string), "$", "%24", -1)

Thanks, Roger.

Russ Cox

unread,
Sep 3, 2010, 1:33:29 PM9/3/10
to Roger Pau Monné, golang-nuts

Every time I read RFC 2396 I see that it is even more
complex than the last time I read it. Trying to puzzle out
the rules for $, I can't tell whether it's okay in query sections
(the text says no, the grammar says yes, the grammar
also allows separators like & and ?, the text explains those,
but the text never explains the meaning of $).

I suppose we could just escape every byte, but that turns
out to cause problems with other (non-conforming) server,
not to mention making things unreadable.

Can you tell me what the meaning of $ is and why it
should be escaped?

Russ

Roger Pau Monné

unread,
Sep 3, 2010, 1:48:02 PM9/3/10
to r...@golang.org, golang-nuts
Well, I use http.URLEscape to query bittorrent trackers, you have to
escape the so called "infohash", which is a 20 byte sha1 sum, and the
trackers won't accept $, it returns "Invalid request", but if I change
"$" for "%24" everything works fine.

Everything is described in this document:
http://bittorrent.org/beps/bep_0003.html

It just says infohash has to be url escaped, it doesn't specify
anything regarding "$", but it won't work if you don't replace it with
"%24". Anyway it took me a long time to realize the problem, since I
assumed URL encoding was something more standard.

2010/9/3 Russ Cox <r...@golang.org>:

Russ Cox

unread,
Sep 3, 2010, 1:52:22 PM9/3/10
to Roger Pau Monné, golang-nuts
On Fri, Sep 3, 2010 at 13:48, Roger Pau Monné <roy...@gmail.com> wrote:
> Well, I use http.URLEscape to query bittorrent trackers, you have to
> escape the so called "infohash", which is a 20 byte sha1 sum, and the
> trackers won't accept $, it returns "Invalid request", but if I change
> "$" for "%24" everything works fine.
>
> Everything is described in this document:
> http://bittorrent.org/beps/bep_0003.html
>
> It just says infohash has to be url escaped, it doesn't specify
> anything regarding "$", but it won't work if you don't replace it with
> "%24". Anyway it took me a long time to realize the problem, since I
> assumed URL encoding was something more standard.

It's described by a standard, but the standard is not terribly clear.
Every different piece of a URL has a slightly different set of
characters that must be escaped, and there's no nice list saying
"here they are". I've created
http://code.google.com/p/go/issues/detail?id=1076
so that we remember to take another stab at this.

Russ

Roger Pau Monné

unread,
Sep 23, 2010, 5:24:17 AM9/23/10
to r...@golang.org, golang-nuts
release.2010-09-22 escapes $ or not? I see the issue is still active.

2010/9/3 Russ Cox <r...@golang.org>:

Cory Mainwaring

unread,
Sep 23, 2010, 11:13:08 AM9/23/10
to Roger Pau Monné, r...@golang.org, golang-nuts
Reading 2.2 of that RFC, $ is definitely reserved, though it's allowed
in most contexts. The problem is that it doesn't do anything in those
contexts. It would seem proper to me to just escape all of the
reserved characters from 2.2, unless the parser takes context into
consideration, in which case I wish you the best of luck puzzling that
out.
Reply all
Reply to author
Forward
0 new messages