Skip to content

Commit baf3ba6

Browse files
committed
Merge branch '2.2'
* 2.2: Fix default value handling for multi-value options [HttpKernel] truncate profiler token to 6 chars (see #7665) Disabled APC on Travis for PHP 5.5+ as it is not available [HttpFoundation] do not use server variable PATH_INFO because it is already decoded and thus symfony is fragile to double encoding of the path Fix download over SSL using IE < 8 and binary file response [Console] Fix merging of application definition, fixes #7068, replaces #7158 [HttpKernel] fixed the Kernel when the ClassLoader component is not available (closes #7406) fixed output of bag values [Yaml] improved boolean naming ($notEOF -> !$EOF) [Yaml] fixed handling an empty value [Routing][XML Loader] Add a possibility to set a default value to null [Console] fixed handling of "0" input on ask The /e modifier for preg_replace() is deprecated in PHP 5.5; replace with preg_replace_callback() fixed handling of "0" input on ask [HttpFoundation] Fixed bug in key searching for NamespacedAttributeBag [Form] DateTimeToRfc3339Transformer use proper transformation exteption in reverse transformation Update PhpEngine.php [PropertyAccess] Add objectives to pluralMap [Security] Removed unused var [HttpFoundation] getClientIp is fixed. Conflicts: src/Symfony/Component/Console/Tests/Command/CommandTest.php src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php src/Symfony/Component/HttpFoundation/Request.php src/Symfony/Component/HttpKernel/Kernel.php
2 parents ed22067 + 0e6fbad commit baf3ba6

File tree

10 files changed

+125
-95
lines changed

10 files changed

+125
-95
lines changed

ApacheRequest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,4 @@ protected function prepareBaseUrl()
4040

4141
return $baseUrl;
4242
}
43-
44-
/**
45-
* {@inheritdoc}
46-
*/
47-
protected function preparePathInfo()
48-
{
49-
return $this->server->get('PATH_INFO') ?: substr($this->prepareRequestUri(), strlen($this->prepareBaseUrl())) ?: '/';
50-
}
5143
}

BinaryFileResponse.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ public function prepare(Request $request)
166166
$this->setProtocolVersion('1.1');
167167
}
168168

169+
$this->ensureIEOverSSLCompatibility($request);
170+
169171
$this->offset = 0;
170172
$this->maxlen = -1;
171173

Request.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,10 @@ public function getClientIps()
684684
$clientIps[] = $ip;
685685

686686
$trustedProxies = self::$trustProxy && !self::$trustedProxies ? array($ip) : self::$trustedProxies;
687+
$ip = $clientIps[0];
687688
$clientIps = array_diff($clientIps, $trustedProxies);
688689

689-
return $clientIps;
690+
return $clientIps ? $clientIps : array($ip);
690691
}
691692

692693
/**

Response.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,7 @@ public function prepare(Request $request)
253253
$this->headers->set('expires', -1);
254254
}
255255

256-
/**
257-
* Check if we need to remove Cache-Control for ssl encrypted downloads when using IE < 9
258-
* @link http://support.microsoft.com/kb/323308
259-
*/
260-
if (false !== stripos($this->headers->get('Content-Disposition'), 'attachment') && preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) == 1 && true === $request->isSecure()) {
261-
if (intval(preg_replace("/(MSIE )(.*?);/", "$2", $match[0])) < 9) {
262-
$this->headers->remove('Cache-Control');
263-
}
264-
}
256+
$this->ensureIEOverSSLCompatibility($request);
265257

266258
return $this;
267259
}
@@ -1179,4 +1171,18 @@ public function isEmpty()
11791171
{
11801172
return in_array($this->statusCode, array(201, 204, 304));
11811173
}
1174+
1175+
/**
1176+
* Check if we need to remove Cache-Control for ssl encrypted downloads when using IE < 9
1177+
*
1178+
* @link http://support.microsoft.com/kb/323308
1179+
*/
1180+
protected function ensureIEOverSSLCompatibility(Request $request)
1181+
{
1182+
if (false !== stripos($this->headers->get('Content-Disposition'), 'attachment') && preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) == 1 && true === $request->isSecure()) {
1183+
if (intval(preg_replace("/(MSIE )(.*?);/", "$2", $match[0])) < 9) {
1184+
$this->headers->remove('Cache-Control');
1185+
}
1186+
}
1187+
}
11821188
}

Session/Attribute/NamespacedAttributeBag.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public function has($name)
4646
$attributes = $this->resolveAttributePath($name);
4747
$name = $this->resolveKey($name);
4848

49+
if (null === $attributes) {
50+
return false;
51+
}
52+
4953
return array_key_exists($name, $attributes);
5054
}
5155

@@ -57,6 +61,10 @@ public function get($name, $default = null)
5761
$attributes = $this->resolveAttributePath($name);
5862
$name = $this->resolveKey($name);
5963

64+
if (null === $attributes) {
65+
return $default;
66+
}
67+
6068
return array_key_exists($name, $attributes) ? $attributes[$name] : $default;
6169
}
6270

@@ -120,12 +128,8 @@ protected function &resolveAttributePath($name, $writeContext = false)
120128
unset($parts[count($parts)-1]);
121129

122130
foreach ($parts as $part) {
123-
if (!array_key_exists($part, $array)) {
124-
if (!$writeContext) {
125-
return $array;
126-
}
127-
128-
$array[$part] = array();
131+
if (null !== $array && !array_key_exists($part, $array)) {
132+
$array[$part] = $writeContext ? array() : null;
129133
}
130134

131135
$array = & $array[$part];

Tests/BinaryFileResponseTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
1717

18-
class BinaryFileResponseTest extends \PHPUnit_Framework_TestCase
18+
class BinaryFileResponseTest extends ResponseTestCase
1919
{
2020
public function testConstruction()
2121
{
@@ -145,4 +145,9 @@ public function getSampleXAccelMappings()
145145
array('/home/foo/bar.txt', '/files/=/var/www/,/baz/=/home/foo/', '/baz/bar.txt'),
146146
);
147147
}
148+
149+
protected function provideResponse()
150+
{
151+
return new BinaryFileResponse('README.md');
152+
}
148153
}

Tests/RequestTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ public function testGetClientIpProvider()
754754
{
755755
return array(
756756
array('88.88.88.88', false, '88.88.88.88', null, null),
757+
array('88.88.88.88', true, '88.88.88.88', null, null),
757758
array('127.0.0.1', false, '127.0.0.1', null, null),
758759
array('::1', false, '::1', null, null),
759760
array('127.0.0.1', false, '127.0.0.1', '88.88.88.88', null),
@@ -762,6 +763,8 @@ public function testGetClientIpProvider()
762763
array('88.88.88.88', true, '123.45.67.89', '127.0.0.1, 87.65.43.21, 88.88.88.88', null),
763764
array('87.65.43.21', true, '123.45.67.89', '127.0.0.1, 87.65.43.21, 88.88.88.88', array('123.45.67.89', '88.88.88.88')),
764765
array('87.65.43.21', false, '123.45.67.89', '127.0.0.1, 87.65.43.21, 88.88.88.88', array('123.45.67.89', '88.88.88.88')),
766+
array('88.88.88.88', true, '123.45.67.89', '88.88.88.88', array('123.45.67.89', '88.88.88.88')),
767+
array('88.88.88.88', false, '123.45.67.89', '88.88.88.88', array('123.45.67.89', '88.88.88.88')),
765768
);
766769
}
767770

Tests/ResponseTest.php

Lines changed: 6 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\Response;
1616

17-
class ResponseTest extends \PHPUnit_Framework_TestCase
17+
class ResponseTest extends ResponseTestCase
1818
{
1919
public function testCreate()
2020
{
@@ -326,75 +326,6 @@ public function testContentTypeCharset()
326326
$this->assertEquals('text/css; charset=UTF-8', $response->headers->get('Content-Type'));
327327
}
328328

329-
public function testNoCacheControlHeaderOnAttachmentUsingHTTPSAndMSIE()
330-
{
331-
// Check for HTTPS and IE 8
332-
$request = new Request();
333-
$request->server->set('HTTPS', true);
334-
$request->server->set('HTTP_USER_AGENT', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)');
335-
336-
$response = new Response();
337-
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
338-
$response->prepare($request);
339-
340-
$this->assertFalse($response->headers->has('Cache-Control'));
341-
342-
// Check for IE 10 and HTTPS
343-
$request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)');
344-
345-
$response = new Response();
346-
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
347-
$response->prepare($request);
348-
349-
$this->assertTrue($response->headers->has('Cache-Control'));
350-
351-
// Check for IE 9 and HTTPS
352-
$request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)');
353-
354-
$response = new Response();
355-
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
356-
$response->prepare($request);
357-
358-
$this->assertTrue($response->headers->has('Cache-Control'));
359-
360-
// Check for IE 9 and HTTP
361-
$request->server->set('HTTPS', false);
362-
363-
$response = new Response();
364-
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
365-
$response->prepare($request);
366-
367-
$this->assertTrue($response->headers->has('Cache-Control'));
368-
369-
// Check for IE 8 and HTTP
370-
$request->server->set('HTTP_USER_AGENT', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)');
371-
372-
$response = new Response();
373-
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
374-
$response->prepare($request);
375-
376-
$this->assertTrue($response->headers->has('Cache-Control'));
377-
378-
// Check for non-IE and HTTPS
379-
$request->server->set('HTTPS', true);
380-
$request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17');
381-
382-
$response = new Response();
383-
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
384-
$response->prepare($request);
385-
386-
$this->assertTrue($response->headers->has('Cache-Control'));
387-
388-
// Check for non-IE and HTTP
389-
$request->server->set('HTTPS', false);
390-
391-
$response = new Response();
392-
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
393-
$response->prepare($request);
394-
395-
$this->assertTrue($response->headers->has('Cache-Control'));
396-
}
397-
398329
public function testPrepareDoesNothingIfContentTypeIsSet()
399330
{
400331
$response = new Response('foo');
@@ -770,6 +701,11 @@ protected function createDateTimeNow()
770701
{
771702
return new \DateTime();
772703
}
704+
705+
protected function provideResponse()
706+
{
707+
return new Response();
708+
}
773709
}
774710

775711
class StringableObject

Tests/ResponseTestCase.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace Symfony\Component\HttpFoundation\Tests;
4+
5+
use Symfony\Component\HttpFoundation\Request;
6+
7+
abstract class ResponseTestCase extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testNoCacheControlHeaderOnAttachmentUsingHTTPSAndMSIE()
10+
{
11+
// Check for HTTPS and IE 8
12+
$request = new Request();
13+
$request->server->set('HTTPS', true);
14+
$request->server->set('HTTP_USER_AGENT', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)');
15+
16+
$response = $this->provideResponse();
17+
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
18+
$response->prepare($request);
19+
20+
$this->assertFalse($response->headers->has('Cache-Control'));
21+
22+
// Check for IE 10 and HTTPS
23+
$request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)');
24+
25+
$response = $this->provideResponse();
26+
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
27+
$response->prepare($request);
28+
29+
$this->assertTrue($response->headers->has('Cache-Control'));
30+
31+
// Check for IE 9 and HTTPS
32+
$request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)');
33+
34+
$response = $this->provideResponse();
35+
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
36+
$response->prepare($request);
37+
38+
$this->assertTrue($response->headers->has('Cache-Control'));
39+
40+
// Check for IE 9 and HTTP
41+
$request->server->set('HTTPS', false);
42+
43+
$response = $this->provideResponse();
44+
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
45+
$response->prepare($request);
46+
47+
$this->assertTrue($response->headers->has('Cache-Control'));
48+
49+
// Check for IE 8 and HTTP
50+
$request->server->set('HTTP_USER_AGENT', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)');
51+
52+
$response = $this->provideResponse();
53+
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
54+
$response->prepare($request);
55+
56+
$this->assertTrue($response->headers->has('Cache-Control'));
57+
58+
// Check for non-IE and HTTPS
59+
$request->server->set('HTTPS', true);
60+
$request->server->set('HTTP_USER_AGENT', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17');
61+
62+
$response = $this->provideResponse();
63+
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
64+
$response->prepare($request);
65+
66+
$this->assertTrue($response->headers->has('Cache-Control'));
67+
68+
// Check for non-IE and HTTP
69+
$request->server->set('HTTPS', false);
70+
71+
$response = $this->provideResponse();
72+
$response->headers->set('Content-Disposition', 'attachment; filename="fname.ext"');
73+
$response->prepare($request);
74+
75+
$this->assertTrue($response->headers->has('Cache-Control'));
76+
}
77+
78+
abstract protected function provideResponse();
79+
}

Tests/Session/Attribute/NamespacedAttributeBagTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,10 @@ public function attributesProvider()
160160
array('csrf.token/b', '4321', true),
161161
array('category', array('fishing' => array('first' => 'cod', 'second' => 'sole')), true),
162162
array('category/fishing', array('first' => 'cod', 'second' => 'sole'), true),
163+
array('category/fishing/missing/first', null, false),
163164
array('category/fishing/first', 'cod', true),
164165
array('category/fishing/second', 'sole', true),
166+
array('category/fishing/missing/second', null, false),
165167
array('user2.login', null, false),
166168
array('never', null, false),
167169
array('bye', null, false),

0 commit comments

Comments
 (0)