Merge pull request #5096 from cakephp/issue-5076

Fix HttpSocket mishandling encoded URIs
This commit is contained in:
José Lorenzo Rodríguez 2014-11-06 10:30:01 +01:00
commit 176473b549
2 changed files with 4 additions and 3 deletions

View file

@ -416,7 +416,8 @@ class HttpSocket extends CakeSocket {
} }
if ($this->request['redirect'] && $this->response->isRedirect()) { if ($this->request['redirect'] && $this->response->isRedirect()) {
$request['uri'] = trim(urldecode($this->response->getHeader('Location')), '='); $location = trim($this->response->getHeader('Location'), '=');
$request['uri'] = str_replace('%2F', '/', $location);
$request['redirect'] = is_int($this->request['redirect']) ? $this->request['redirect'] - 1 : $this->request['redirect']; $request['redirect'] = is_int($this->request['redirect']) ? $this->request['redirect'] - 1 : $this->request['redirect'];
$this->response = $this->request($request); $this->response = $this->request($request);
} }

View file

@ -786,7 +786,7 @@ class HttpSocketTest extends CakeTestCase {
'uri' => 'http://localhost/oneuri', 'uri' => 'http://localhost/oneuri',
'redirect' => 1 'redirect' => 1
); );
$serverResponse1 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://i.cmpnet.com%2Ftechonline%2Fpdf%2Fa.pdf=\r\n\r\n"; $serverResponse1 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://i.cmpnet.com%2Ftechonline%2Fpdf%2Fa+b.pdf=\r\n\r\n";
$serverResponse2 = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>You have been redirected</h1>"; $serverResponse2 = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>You have been redirected</h1>";
$this->Socket->expects($this->at(1)) $this->Socket->expects($this->at(1))
@ -797,7 +797,7 @@ class HttpSocketTest extends CakeTestCase {
->method('write') ->method('write')
->with($this->logicalAnd( ->with($this->logicalAnd(
$this->stringContains('Host: i.cmpnet.com'), $this->stringContains('Host: i.cmpnet.com'),
$this->stringContains('GET /techonline/pdf/a.pdf') $this->stringContains('GET /techonline/pdf/a+b.pdf')
)); ));
$this->Socket->expects($this->at(4)) $this->Socket->expects($this->at(4))