Problem with ampersand in query string

1,358 views
Skip to first unread message

gmalquestion

unread,
Oct 31, 2008, 5:49:18 AM10/31/08
to Google App Engine
I have javascript call which deletes an url from the user's
subscription. It looks like this:

anchor.href = "javascript:window.location.href='delete?url=" +
encodeURIComponent(url) + "'";

The problem is the handler on appengine doesn't process the parameter
properly if it has an ampersand in it. For example, the url

http://server/stuff?a=b&c=d

is passed to appengine as

delete?url=http://server/stuff?a=b&c=d

so it thinks the url parameter ends at the ampersand:

url=http://server/stuff?a=b

That's why I used encodeURIComponent, but it didn't help. I also tried
escape and encode, but they didn't work either.

Can it be a problem on the appengine part (incorrect query parameter
processing) or I should do something else in addition to
encodeURIComponent?

Peter Recore

unread,
Oct 31, 2008, 8:38:14 AM10/31/08
to Google App Engine
what does the url that your javascript is generating look like? It
should look like this:

delete?url=http%3A%2F%2Fserver%2Fstuff%3Fa%3Db%26c%3Dd

But you say your app is passing "delete?url=http://server/stuff?
a=b&c=d" to app engine.

If so, it sounds like you have a javascript problem, not a app engine
problem.

-peter

gmalquestion

unread,
Oct 31, 2008, 12:26:30 PM10/31/08
to Google App Engine
I found the root of problem:

The assignment setting up the link

anchor.href = "javascript:window.location.href='delete?url=" +
encodeURIComponent(url) + "'";

is incorrect, because it destroys the effects of encodeURIComponent
(the %-sequences are stored as normal characters), so an additional
escape is needed to prevent this:

anchor.href = "javascript:window.location.href='delete?url=" +
escape(encodeURIComponent(url)) + "'";

Reply all
Reply to author
Forward
0 new messages