views:

34

answers:

2

I have a Selenium/PHPUnit test that needs to open a URL that contains an encoded URL.

$redirectToLocation = urlencode('/myothercontroller/action'); // %2Fmyothercontroller%2Faction
$this->openAndWait('/controller/action/thenRedirectTo/' . $redirectToLocation);

But when I run my test, the browser tried opening the decoded URL:

/controller/action/thenRedirectTo//myothercontroller/action

What should I do to get selenium to open the encoded URL?

Update: Actually...turns out selenium is doing it's job, but Apache is decoding the URL before it gets to the controller:

The requested URL /controller/action/thenRedirectTo//myothercontroller/action was not found on this server.

How should I fix this problem?

Update: Here's a whole conversation about the same problem that I'm having: http://old.nabble.com/URL-Encoding-td18850769.html. Their workaround was to base64 encode the url, but that's not good enough for me. I may use this solution in the short term, but I want to know what is the real cause of this problem, so I can eliminate it.

A: 

Interesting problem. I've personally never had any problems passing another URL in a query string, i.e. /controller/action/thenRedirectTo?q=%2Fmyothercontroller%2Faction , but I haven't used Apache in a long time, and that's not exactly what you're trying to do.

One possible solution could be double url encoding it.

$redirectToLocation = urlencode(urlencode('/myothercontroller/action'));
$this->openAndWait('/controller/action/thenRedirectTo/' . $redirectToLocation);

Perhaps Apache will only url decode it one level.

mellowsoon
A: 

I've encountered this behavior before and it was mod_rewrite that was doing the decoding. As far as I know the only way to get around it is urlencode the portion of the request URL that needs to preserve special characters twice.

Jeff Busby