From 253eebad881573cf119a01b5f71bc032457ab522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20G=C3=B3recki?= Date: Tue, 10 Jan 2012 11:06:00 +0100 Subject: [PATCH 1/8] [BugFix][Validator] Fix for PHP incosistent behaviour of ArrayAccess Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: #2779 Todo: - Because PHP function `array_key_exists` is buggy, it works great with native PHP `ArrayObject` instances, but hand written implementations of `ArrayAccess` and `Traversable` objects will fail to work with `CollectionValidator` --- .../Component/Validator/Constraints/CollectionValidator.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Validator/Constraints/CollectionValidator.php b/src/Symfony/Component/Validator/Constraints/CollectionValidator.php index 67ede37b19..e703b538e0 100644 --- a/src/Symfony/Component/Validator/Constraints/CollectionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CollectionValidator.php @@ -52,7 +52,11 @@ class CollectionValidator extends ConstraintValidator } foreach ($constraint->fields as $field => $constraints) { - if (array_key_exists($field, $value)) { + if ( + // bug fix issue #2779 + (is_array($value) && array_key_exists($field, $value)) || + ($value instanceof \ArrayAccess && $value->offsetExists($field)) + ) { // cannot simply cast to array, because then the object is converted to an // array instead of wrapped inside $constraints = is_array($constraints) ? $constraints : array($constraints); From 7f7c2a7094cda4a211acf526d2329523730b6da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20G=C3=B3recki?= Date: Tue, 10 Jan 2012 11:09:32 +0100 Subject: [PATCH 2/8] Add prof-of-concept test, this test will fail without changes in previous commit --- .../Constraints/CollectionValidatorTest.php | 203 +++++++++++++++--- 1 file changed, 179 insertions(+), 24 deletions(-) diff --git a/tests/Symfony/Tests/Component/Validator/Constraints/CollectionValidatorTest.php b/tests/Symfony/Tests/Component/Validator/Constraints/CollectionValidatorTest.php index 8429a3eacc..a2f17c3c44 100644 --- a/tests/Symfony/Tests/Component/Validator/Constraints/CollectionValidatorTest.php +++ b/tests/Symfony/Tests/Component/Validator/Constraints/CollectionValidatorTest.php @@ -13,9 +13,71 @@ namespace Symfony\Tests\Component\Validator\Constraints; use Symfony\Component\Validator\ExecutionContext; use Symfony\Component\Validator\Constraints\Min; +use Symfony\Component\Validator\Constraints\NotBlank; +use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\Constraints\Collection; use Symfony\Component\Validator\Constraints\CollectionValidator; +/** + * This class is a hand written simplified version of PHP native `ArrayObject` + * class, to show that it behaves different than PHP native implementation. + */ +class TestArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable +{ + private $array; + + public function __construct(array $array = null) + { + $this->array = (array) ($array ?: array()); + } + + public function offsetExists($offset) + { + return array_key_exists($offset, $this->array); + } + + public function offsetGet($offset) + { + return $this->array[$offset]; + } + + public function offsetSet($offset, $value) + { + if (null === $offset) { + $this->array[] = $value; + } else { + $this->array[$offset] = $value; + } + } + + public function offsetUnset($offset) + { + if (array_key_exists($offset, $this->array)) { + unset($this->array[$offset]); + } + } + + public function getIterator() + { + return new \ArrayIterator($this->array); + } + + public function count() + { + return count($this->array); + } + + public function serialize() + { + return serialize($this->array); + } + + public function unserialize($serialized) + { + $this->array = (array) unserialize((string) $serialized); + } +} + class CollectionValidatorTest extends \PHPUnit_Framework_TestCase { protected $validator; @@ -49,15 +111,22 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase public function testFieldsAsDefaultOption() { - $this->validator->isValid(array('foo' => 'foobar'), new Collection(array( + $this->assertTrue($this->validator->isValid(array('foo' => 'foobar'), new Collection(array( 'foo' => new Min(4), - ))); + )))); + $this->assertTrue($this->validator->isValid(new \ArrayObject(array('foo' => 'foobar')), new Collection(array( + 'foo' => new Min(4), + )))); + $this->assertTrue($this->validator->isValid(new TestArrayObject(array('foo' => 'foobar')), new Collection(array( + 'foo' => new Min(4), + )))); } + /** + * @expectedException Symfony\Component\Validator\Exception\UnexpectedTypeException + */ public function testThrowsExceptionIfNotTraversable() { - $this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException'); - $this->validator->isValid('foobar', new Collection(array('fields' => array( 'foo' => new Min(4), )))); @@ -112,13 +181,11 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase )))); } - public function testExtraFieldsDisallowed() + /** + * @dataProvider getArgumentsWithExtraFields + */ + public function testExtraFieldsDisallowed($array) { - $array = array( - 'foo' => 5, - 'bar' => 6, - ); - $this->assertFalse($this->validator->isValid($array, new Collection(array( 'fields' => array( 'foo' => new Min(4), @@ -132,12 +199,15 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase $array = array( 'foo' => null, ); - - $this->assertTrue($this->validator->isValid($array, new Collection(array( + $collection = new Collection(array( 'fields' => array( 'foo' => new Min(4), ), - )))); + )); + + $this->assertTrue($this->validator->isValid($array, $collection)); + $this->assertTrue($this->validator->isValid(new \ArrayObject($array), $collection)); + $this->assertTrue($this->validator->isValid(new TestArrayObject($array), $collection)); } public function testExtraFieldsAllowed() @@ -146,13 +216,16 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase 'foo' => 5, 'bar' => 6, ); - - $this->assertTrue($this->validator->isValid($array, new Collection(array( + $collection = new Collection(array( 'fields' => array( 'foo' => new Min(4), ), 'allowExtraFields' => true, - )))); + )); + + $this->assertTrue($this->validator->isValid($array, $collection)); + $this->assertTrue($this->validator->isValid(new \ArrayObject($array), $collection)); + $this->assertTrue($this->validator->isValid(new TestArrayObject($array), $collection)); } public function testMissingFieldsDisallowed() @@ -162,6 +235,16 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase 'foo' => new Min(4), ), )))); + $this->assertFalse($this->validator->isValid(new \ArrayObject(array()), new Collection(array( + 'fields' => array( + 'foo' => new Min(4), + ), + )))); + $this->assertFalse($this->validator->isValid(new TestArrayObject(array()), new Collection(array( + 'fields' => array( + 'foo' => new Min(4), + ), + )))); } public function testMissingFieldsAllowed() @@ -172,16 +255,58 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase ), 'allowMissingFields' => true, )))); + $this->assertTrue($this->validator->isValid(new \ArrayObject(array()), new Collection(array( + 'fields' => array( + 'foo' => new Min(4), + ), + 'allowMissingFields' => true, + )))); + $this->assertTrue($this->validator->isValid(new TestArrayObject(array()), new Collection(array( + 'fields' => array( + 'foo' => new Min(4), + ), + 'allowMissingFields' => true, + )))); } - public function getValidArguments() - { - return array( - // can only test for one entry, because PHPUnits mocking does not allow - // to expect multiple method calls with different arguments - array(array('foo' => 3)), - array(new \ArrayObject(array('foo' => 3))), - ); + public function testArrayAccessObject() { + $value = new TestArrayObject(); + $value['foo'] = 12; + $value['asdf'] = 'asdfaf'; + + $this->assertTrue(isset($value['asdf'])); + $this->assertTrue(isset($value['foo'])); + $this->assertFalse(empty($value['asdf'])); + $this->assertFalse(empty($value['foo'])); + + $result = $this->validator->isValid($value, new Collection(array( + 'fields' => array( + 'foo' => new NotBlank(), + 'asdf' => new NotBlank() + ) + ))); + + $this->assertTrue($result); + } + + public function testArrayObject() { + $value = new \ArrayObject(array()); + $value['foo'] = 12; + $value['asdf'] = 'asdfaf'; + + $this->assertTrue(isset($value['asdf'])); + $this->assertTrue(isset($value['foo'])); + $this->assertFalse(empty($value['asdf'])); + $this->assertFalse(empty($value['foo'])); + + $result = $this->validator->isValid($value, new Collection(array( + 'fields' => array( + 'foo' => new NotBlank(), + 'asdf' => new NotBlank() + ) + ))); + + $this->assertTrue($result); } public function testObjectShouldBeLeftUnchanged() @@ -199,4 +324,34 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase 'foo' => 3 ), (array) $value); } + + public function getValidArguments() + { + return array( + // can only test for one entry, because PHPUnits mocking does not allow + // to expect multiple method calls with different arguments + array(array('foo' => 3)), + array(new \ArrayObject(array('foo' => 3))), + array(new TestArrayObject(array('foo' => 3))), + ); + } + + public function getArgumentsWithExtraFields() + { + return array( + array(array( + 'foo' => 5, + 'bar' => 6, + )), + array(new \ArrayObject(array( + 'foo' => 5, + 'bar' => 6, + ))), + array(new TestArrayObject(array( + 'foo' => 5, + 'bar' => 6, + ))) + ); + } } + From fe62401907d7f2fce2a47d149f3a71dfebd508ef Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Wed, 11 Jan 2012 11:20:58 -0800 Subject: [PATCH 3/8] optimized string starts with checks Doing this with strpos() is slightly faster than substr(). --- .../Bundle/TwigBundle/DependencyInjection/Configuration.php | 2 +- src/Symfony/Component/BrowserKit/Client.php | 2 +- src/Symfony/Component/Console/Input/ArgvInput.php | 2 +- src/Symfony/Component/Console/Input/ArrayInput.php | 2 +- src/Symfony/Component/Console/Input/InputOption.php | 2 +- src/Symfony/Component/DomCrawler/Link.php | 2 +- src/Symfony/Component/HttpFoundation/Response.php | 2 +- src/Symfony/Component/HttpFoundation/ServerBag.php | 2 +- src/Symfony/Component/HttpKernel/Kernel.php | 2 +- .../Component/HttpKernel/Profiler/MysqlProfilerStorage.php | 2 +- .../Component/HttpKernel/Profiler/SqliteProfilerStorage.php | 2 +- src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php | 2 +- src/Symfony/Component/Yaml/Parser.php | 6 +++--- 13 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php index b7bc1b9313..f340bc3c79 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php @@ -79,7 +79,7 @@ class Configuration implements ConfigurationInterface ->useAttributeAsKey('key') ->prototype('array') ->beforeNormalization() - ->ifTrue(function($v){ return is_string($v) && '@' === substr($v, 0, 1); }) + ->ifTrue(function($v){ return is_string($v) && 0 === strpos($v, '@'); }) ->then(function($v){ return array('id' => substr($v, 1), 'type' => 'service'); }) ->end() ->beforeNormalization() diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index 5b3b628268..9d3bda69cf 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -441,7 +441,7 @@ abstract class Client protected function getAbsoluteUri($uri) { // already absolute? - if ('http' === substr($uri, 0, 4)) { + if (0 === strpos($uri, 'http')) { return $uri; } diff --git a/src/Symfony/Component/Console/Input/ArgvInput.php b/src/Symfony/Component/Console/Input/ArgvInput.php index 122cbb3fda..dda022206c 100644 --- a/src/Symfony/Component/Console/Input/ArgvInput.php +++ b/src/Symfony/Component/Console/Input/ArgvInput.php @@ -77,7 +77,7 @@ class ArgvInput extends Input { $this->parsed = $this->tokens; while (null !== $token = array_shift($this->parsed)) { - if ('--' === substr($token, 0, 2)) { + if (0 === strpos($token, '--')) { $this->parseLongOption($token); } elseif ('-' === $token[0]) { $this->parseShortOption($token); diff --git a/src/Symfony/Component/Console/Input/ArrayInput.php b/src/Symfony/Component/Console/Input/ArrayInput.php index a774c08a8f..c9d8ee98a3 100644 --- a/src/Symfony/Component/Console/Input/ArrayInput.php +++ b/src/Symfony/Component/Console/Input/ArrayInput.php @@ -116,7 +116,7 @@ class ArrayInput extends Input protected function parse() { foreach ($this->parameters as $key => $value) { - if ('--' === substr($key, 0, 2)) { + if (0 === strpos($key, '--')) { $this->addLongOption(substr($key, 2), $value); } elseif ('-' === $key[0]) { $this->addShortOption(substr($key, 1), $value); diff --git a/src/Symfony/Component/Console/Input/InputOption.php b/src/Symfony/Component/Console/Input/InputOption.php index 15aa2f8188..cc609df756 100644 --- a/src/Symfony/Component/Console/Input/InputOption.php +++ b/src/Symfony/Component/Console/Input/InputOption.php @@ -46,7 +46,7 @@ class InputOption */ public function __construct($name, $shortcut = null, $mode = null, $description = '', $default = null) { - if ('--' === substr($name, 0, 2)) { + if (0 === strpos($name, '--')) { $name = substr($name, 2); } diff --git a/src/Symfony/Component/DomCrawler/Link.php b/src/Symfony/Component/DomCrawler/Link.php index 6367c88da2..39ddb8ca97 100644 --- a/src/Symfony/Component/DomCrawler/Link.php +++ b/src/Symfony/Component/DomCrawler/Link.php @@ -80,7 +80,7 @@ class Link $uri = trim($this->getRawUri()); // absolute URL? - if ('http' === substr($uri, 0, 4)) { + if (0 === strpos($uri, 'http')) { return $uri; } diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 8732e8261b..daf196b104 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -134,7 +134,7 @@ class Response $charset = $this->charset ?: 'UTF-8'; if (!$this->headers->has('Content-Type')) { $this->headers->set('Content-Type', 'text/html; charset='.$charset); - } elseif ('text/' === substr($this->headers->get('Content-Type'), 0, 5) && false === strpos($this->headers->get('Content-Type'), 'charset')) { + } elseif (0 === strpos($this->headers->get('Content-Type'), 'text/') && false === strpos($this->headers->get('Content-Type'), 'charset')) { // add the charset $this->headers->set('Content-Type', $this->headers->get('Content-Type').'; charset='.$charset); } diff --git a/src/Symfony/Component/HttpFoundation/ServerBag.php b/src/Symfony/Component/HttpFoundation/ServerBag.php index 02db3b1819..9cb7786129 100644 --- a/src/Symfony/Component/HttpFoundation/ServerBag.php +++ b/src/Symfony/Component/HttpFoundation/ServerBag.php @@ -23,7 +23,7 @@ class ServerBag extends ParameterBag { $headers = array(); foreach ($this->parameters as $key => $value) { - if ('HTTP_' === substr($key, 0, 5)) { + if (0 === strpos($key, 'HTTP_')) { $headers[substr($key, 5)] = $value; } // CONTENT_* are not prefixed with HTTP_ diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index ba4cf30f79..8a3b787d8c 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -597,7 +597,7 @@ abstract class Kernel implements KernelInterface { $parameters = array(); foreach ($_SERVER as $key => $value) { - if ('SYMFONY__' === substr($key, 0, 9)) { + if (0 === strpos($key, 'SYMFONY__')) { $parameters[strtolower(str_replace('__', '.', substr($key, 9)))] = $value; } } diff --git a/src/Symfony/Component/HttpKernel/Profiler/MysqlProfilerStorage.php b/src/Symfony/Component/HttpKernel/Profiler/MysqlProfilerStorage.php index c78f836ec7..d40608d2e6 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/MysqlProfilerStorage.php +++ b/src/Symfony/Component/HttpKernel/Profiler/MysqlProfilerStorage.php @@ -24,7 +24,7 @@ class MysqlProfilerStorage extends PdoProfilerStorage protected function initDb() { if (null === $this->db) { - if ('mysql' !== substr($this->dsn, 0, 5)) { + if (0 !== strpos($this->dsn, 'mysql')) { throw new \RuntimeException('Please check your configuration. You are trying to use Mysql with a wrong dsn. "'.$this->dsn.'"'); } diff --git a/src/Symfony/Component/HttpKernel/Profiler/SqliteProfilerStorage.php b/src/Symfony/Component/HttpKernel/Profiler/SqliteProfilerStorage.php index cb46ad98a9..5d7b93df98 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/SqliteProfilerStorage.php +++ b/src/Symfony/Component/HttpKernel/Profiler/SqliteProfilerStorage.php @@ -25,7 +25,7 @@ class SqliteProfilerStorage extends PdoProfilerStorage protected function initDb() { if (null === $this->db || $this->db instanceof \SQLite3) { - if ('sqlite' !== substr($this->dsn, 0, 6 )) { + if (0 !== strpos($this->dsn, 'sqlite')) { throw new \RuntimeException('You are trying to use Sqlite with a wrong dsn. "'.$this->dsn.'"'); } if (class_exists('SQLite3')) { diff --git a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php index bf73fc3572..b53d55967a 100644 --- a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php @@ -431,7 +431,7 @@ class StubIntlDateFormatter $timeZone = $timeZoneId; // Get an Etc/GMT time zone that is accepted for \DateTimeZone - if ('GMT' !== $timeZoneId && 'GMT' === substr($timeZoneId, 0, 3)) { + if ('GMT' !== $timeZoneId && 0 === strpos($timeZoneId, 'GMT')) { try { $timeZoneId = DateFormat\TimeZoneTransformer::getEtcTimeZoneId($timeZoneId); } catch (\InvalidArgumentException $e) { diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 653047cc6c..074306969a 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -114,7 +114,7 @@ class Parser } if ('<<' === $key) { - if (isset($values['value']) && '*' === substr($values['value'], 0, 1)) { + if (isset($values['value']) && 0 === strpos($values['value'], '*')) { $isInPlace = substr($values['value'], 1); if (!array_key_exists($isInPlace, $this->refs)) { throw new ParseException(sprintf('Reference "%s" does not exist.', $isInPlace), $this->getRealCurrentLineNb() + 1, $this->currentLine); @@ -188,7 +188,7 @@ class Parser if (is_array($value)) { $first = reset($value); - if (is_string($first) && '*' === substr($first, 0, 1)) { + if (is_string($first) && 0 === strpos($first, '*')) { $data = array(); foreach ($value as $alias) { $data[] = $this->refs[substr($alias, 1)]; @@ -347,7 +347,7 @@ class Parser */ private function parseValue($value) { - if ('*' === substr($value, 0, 1)) { + if (0 === strpos($value, '*')) { if (false !== $pos = strpos($value, '#')) { $value = substr($value, 1, $pos - 2); } else { From 7f7f82a53e7f5bbc6c4143e2abf37412301ea677 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Thu, 12 Jan 2012 09:33:03 -0800 Subject: [PATCH 4/8] [HttpKernel] removed unnecessary regex The pattern was also flawed because of the unescaped `.` --- src/Symfony/Component/HttpKernel/HttpCache/Esi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/HttpCache/Esi.php b/src/Symfony/Component/HttpKernel/HttpCache/Esi.php index 3ac0e49587..2c48163c17 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/Esi.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/Esi.php @@ -64,7 +64,7 @@ class Esi return false; } - return (Boolean) preg_match('#ESI/1.0#', $value); + return false !== strpos($value, 'ESI/1.0'); } /** From efce640a5ef93b147e5f7a984d4454772a2eca80 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 13 Jan 2012 10:48:50 +0200 Subject: [PATCH 5/8] [Yaml][Parser] throw an exception if not readable --- src/Symfony/Component/Yaml/Yaml.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Yaml/Yaml.php b/src/Symfony/Component/Yaml/Yaml.php index aad88fdc19..e9a34ea0c4 100644 --- a/src/Symfony/Component/Yaml/Yaml.php +++ b/src/Symfony/Component/Yaml/Yaml.php @@ -47,7 +47,14 @@ class Yaml $file = ''; // if input is a file, process it - if (strpos($input, "\n") === false && is_file($input) && is_readable($input)) { + if (strpos($input, "\n") === false && is_file($input)) { + if (false === is_readable($input)) { + throw new \InvalidArgumentException(sprintf( + 'The service file "%s" is not readable.', + $input + )); + } + $file = $input; ob_start(); From 79610141401fd901a886c430ea526315af8ef1f1 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 13 Jan 2012 17:48:38 +0200 Subject: [PATCH 6/8] [Yaml][Parser] changes according review --- src/Symfony/Component/Yaml/Yaml.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Symfony/Component/Yaml/Yaml.php b/src/Symfony/Component/Yaml/Yaml.php index e9a34ea0c4..a59ce86f48 100644 --- a/src/Symfony/Component/Yaml/Yaml.php +++ b/src/Symfony/Component/Yaml/Yaml.php @@ -49,10 +49,7 @@ class Yaml // if input is a file, process it if (strpos($input, "\n") === false && is_file($input)) { if (false === is_readable($input)) { - throw new \InvalidArgumentException(sprintf( - 'The service file "%s" is not readable.', - $input - )); + throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $input)); } $file = $input; From d67d419f3c4d9a7cf863d7239c23318f64be6bbe Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Fri, 13 Jan 2012 11:05:57 -0800 Subject: [PATCH 7/8] [HttpFoundation] added missing trustProxy condition --- src/Symfony/Component/HttpFoundation/Request.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index eb5affe93e..3a20ed90c5 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -562,7 +562,11 @@ class Request */ public function getPort() { - return $this->headers->get('X-Forwarded-Port') ?: $this->server->get('SERVER_PORT'); + if (self::$trustProxy && $this->headers->has('X-Forwarded-Port')) { + return $this->headers->get('X-Forwarded-Port'); + } else { + return $this->server->get('SERVER_PORT'); + } } /** From 33f68fe8214c42f3a2d3667ddab2cc518685a754 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 16 Jan 2012 07:41:41 +0100 Subject: [PATCH 8/8] added a missing use statement --- src/Symfony/Bundle/FrameworkBundle/HttpKernel.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php index e598a32236..fe44fe0131 100644 --- a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\FrameworkBundle; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; use Symfony\Component\DependencyInjection\ContainerInterface;