Skip to content

Commit

Permalink
Merge branch '2.1' into 2.2
Browse files Browse the repository at this point in the history
* 2.1:
  [HttpFoundation][BrowserKit] fixed path when converting a cookie to a string
  [BrowserKit] removed dead code
  [HttpFoundation] fixed empty domain= in Cookie::__toString()
  fixed detection of secure cookies received over https
  [Translation] removed an uneeded class property
  [Translation] removed unneeded getter/setter
  [Translator] added additional conversion for encodings other than utf-8
  fix a DI circular reference recognition bug
  [HttpFoundation] fixed the creation of sub-requests under some circumstances for IIS
  • Loading branch information
fabpot committed Apr 20, 2013
2 parents 0e6fbad + 294ecc2 commit 6519576
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ public function __toString()
}
}

if ('/' !== $this->path) {
if ($this->path) {
$str .= '; path='.$this->path;
}

if (null !== $this->getDomain()) {
if ($this->getDomain()) {
$str .= '; domain='.$this->getDomain();
}

Expand Down
7 changes: 5 additions & 2 deletions Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1489,11 +1489,14 @@ protected function prepareRequestUri()
{
$requestUri = '';

if ($this->headers->has('X_ORIGINAL_URL') && false !== stripos(PHP_OS, 'WIN')) {
if ($this->headers->has('X_ORIGINAL_URL')) {
// IIS with Microsoft Rewrite Module
$requestUri = $this->headers->get('X_ORIGINAL_URL');
$this->headers->remove('X_ORIGINAL_URL');
} elseif ($this->headers->has('X_REWRITE_URL') && false !== stripos(PHP_OS, 'WIN')) {
$this->server->remove('HTTP_X_ORIGINAL_URL');
$this->server->remove('UNENCODED_URL');
$this->server->remove('IIS_WasUrlRewritten');
} elseif ($this->headers->has('X_REWRITE_URL')) {
// IIS with ISAPI_Rewrite
$requestUri = $this->headers->get('X_REWRITE_URL');
$this->headers->remove('X_REWRITE_URL');
Expand Down
7 changes: 4 additions & 3 deletions Tests/CookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,12 @@ public function testCookieIsCleared()
public function testToString()
{
$cookie = new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true);

$this->assertEquals('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; domain=.myfoodomain.com; secure; httponly', $cookie->__toString(), '->__toString() returns string representation of the cookie');
$this->assertEquals('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly', $cookie->__toString(), '->__toString() returns string representation of the cookie');

$cookie = new Cookie('foo', null, 1, '/admin/', '.myfoodomain.com');

$this->assertEquals('foo=deleted; expires=' . gmdate("D, d-M-Y H:i:s T", time()-31536001) . '; path=/admin/; domain=.myfoodomain.com; httponly', $cookie->__toString(), '->__toString() returns string representation of a cleared cookie if value is NULL');

$cookie = new Cookie('foo', 'bar', 0, '/', '');
$this->assertEquals('foo=bar; path=/; httponly', $cookie->__toString());
}
}
89 changes: 89 additions & 0 deletions Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,95 @@ public function testTrustedProxies()
// reset
Request::setTrustedProxies(array());
}

/**
* @dataProvider iisRequestUriProvider
*/
public function testIISRequestUri($headers, $server, $expectedRequestUri)
{
$request = new Request();
$request->headers->replace($headers);
$request->server->replace($server);

$this->assertEquals($expectedRequestUri, $request->getRequestUri(), '->getRequestUri() is correct');

$subRequestUri = '/bar/foo';
$subRequest = $request::create($subRequestUri, 'get', array(), array(), array(), $request->server->all());
$this->assertEquals($subRequestUri, $subRequest->getRequestUri(), '->getRequestUri() is correct in sub request');
}

public function iisRequestUriProvider()
{
return array(
array(
array(
'X_ORIGINAL_URL' => '/foo/bar',
),
array(),
'/foo/bar'
),
array(
array(
'X_REWRITE_URL' => '/foo/bar',
),
array(),
'/foo/bar'
),
array(
array(),
array(
'IIS_WasUrlRewritten' => '1',
'UNENCODED_URL' => '/foo/bar'
),
'/foo/bar'
),
array(
array(
'X_ORIGINAL_URL' => '/foo/bar',
),
array(
'HTTP_X_ORIGINAL_URL' => '/foo/bar'
),
'/foo/bar'
),
array(
array(
'X_ORIGINAL_URL' => '/foo/bar',
),
array(
'IIS_WasUrlRewritten' => '1',
'UNENCODED_URL' => '/foo/bar'
),
'/foo/bar'
),
array(
array(
'X_ORIGINAL_URL' => '/foo/bar',
),
array(
'HTTP_X_ORIGINAL_URL' => '/foo/bar',
'IIS_WasUrlRewritten' => '1',
'UNENCODED_URL' => '/foo/bar'
),
'/foo/bar'
),
array(
array(),
array(
'ORIG_PATH_INFO' => '/foo/bar',
),
'/foo/bar'
),
array(
array(),
array(
'ORIG_PATH_INFO' => '/foo/bar',
'QUERY_STRING' => 'foo=bar',
),
'/foo/bar?foo=bar'
)
);
}
}

class RequestContentProxy extends Request
Expand Down
6 changes: 3 additions & 3 deletions Tests/ResponseHeaderBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ public function testToStringIncludesCookieHeaders()
$bag = new ResponseHeaderBag(array());
$bag->setCookie(new Cookie('foo', 'bar'));

$this->assertContains("Set-Cookie: foo=bar; httponly", explode("\r\n", $bag->__toString()));
$this->assertContains("Set-Cookie: foo=bar; path=/; httponly", explode("\r\n", $bag->__toString()));

$bag->clearCookie('foo');

$this->assertContains("Set-Cookie: foo=deleted; expires=".gmdate("D, d-M-Y H:i:s T", time() - 31536001)."; httponly", explode("\r\n", $bag->__toString()));
$this->assertContains("Set-Cookie: foo=deleted; expires=".gmdate("D, d-M-Y H:i:s T", time() - 31536001)."; path=/; httponly", explode("\r\n", $bag->__toString()));
}

public function testReplace()
Expand Down Expand Up @@ -158,7 +158,7 @@ public function testCookiesWithSameNames()
$this->assertContains("Set-Cookie: foo=bar; path=/path/foo; domain=foo.bar; httponly", $headers);
$this->assertContains("Set-Cookie: foo=bar; path=/path/foo; domain=foo.bar; httponly", $headers);
$this->assertContains("Set-Cookie: foo=bar; path=/path/bar; domain=bar.foo; httponly", $headers);
$this->assertContains("Set-Cookie: foo=bar; httponly", $headers);
$this->assertContains("Set-Cookie: foo=bar; path=/; httponly", $headers);

$cookies = $bag->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
$this->assertTrue(isset($cookies['foo.bar']['/path/foo']['foo']));
Expand Down

0 comments on commit 6519576

Please sign in to comment.