I am testing my Zend Framework application using Selenium and PHPUnit. I have a 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 it seems as if 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.
Update: I have a co-worker who thinks there may be a problem with the way Zend Framework is routing the request. Do you think that could be the case?
This is an Apache "feature". Encoded slashes are automatically decoded and sent to the application (php). Therefore it's recognized as one long uri instead of an uri with an encoded uri as parameter.
Nevertheless, it's possible to turn this off, by using AllowEncodedSlashes On
in your configuration. More information at the Apache manual. Please note the context of this directive is server config and virtual host so you cannot place it in a .htaccess file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With