dstarh
dstarh

Reputation: 5076

Play Framework double url encoding

given the following controller method where username = bob and emailAddress = [email protected]

    public static void resetPassword(String username, String emailAddress) {

            String url = BASE_URL + "/users/" + username + "/reset_password";

            HttpResponse response = WS.url(url).setParameter("email_address", emailAddress).get();
}

Sometimes when I make the call the url endpoing receives:

localhost:8080/api/v1/users/bob/reset_password?email_address=bob%40bob.com

then other times i get: localhost:8080/api/v1/users/bob/reset_password?email_address=bob%2540bob.com

On the second one the @ has been encoded once to %40 then the % was again encoded to %25 so you end up with %2540

If I do nothing more than wait a minute the problem goes away which makes me think it's some sort of caching problem but I can't seem to figure out what it is.

Upvotes: 6

Views: 2850

Answers (4)

dstarh
dstarh

Reputation: 5076

finally been recognized as a bug and has been fixed in a later release

Upvotes: 4

Roland Illig
Roland Illig

Reputation: 41625

I suspect some form of URL rewriting. Do you have an Apache Web Server running in front of your server? Maybe some RewriteRule is missing the [NE] flag.

Upvotes: 0

grahamrb
grahamrb

Reputation: 2269

I think what is happening is when you are calling the controller the first time you send the at symbol as an at symbol.

This then gets encoded into the response and the @ is converted to %40. I'm guessing when you get this back and you resend it through the browser the % in the %40 gets encoded to %25 making it %2540.

Sorry if the above is confusing, it is difficult to explain.

Simple answer would be to just do a replace on the emailAddress variable of %40 to @ before passing it into WS class. There is also a urlDecode() method in the play framework which may do the trick, I've used play before but I haven't used this method.

Upvotes: 0

gil
gil

Reputation: 181

since this does not repeduce all the times i dont know if that will help but did you try to encode the url? for example : org.apache.commons.httpclient.util.URIUtil.encodeAll(url);

Upvotes: 0

Related Questions