8000 Merge branch '2.7' into 2.8 · symfony/symfony@e1ab801 · GitHub
[go: up one dir, main page]

Skip to content

Commit e1ab801

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [Validator] Add object handling of invalid constraints in Composite [HttpFoundation] Fix Request::getHost() when having several hosts in X_FORWARDED_HOST
2 parents 8aefa27 + d562cac commit e1ab801

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ public function getPort()
968968
{
969969
if ($this->isFromTrustedProxy()) {
970970
if (self::$trustedHeaders[self::HEADER_CLIENT_PORT] && $port = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PORT])) {
971-
return $port;
971+
return (int) $port;
972972
}
973973

974974
if (self::$trustedHeaders[self::HEADER_CLIENT_PROTO] && 'https' === $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO], 'http')) {
@@ -1217,9 +1217,9 @@ public function isSecure()
12171217
public function getHost()
12181218
{
12191219
if ($this->isFromTrustedProxy() && self::$trustedHeaders[self::HEADER_CLIENT_HOST] && $host = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_HOST])) {
1220-
$elements = explode(',', $host);
1220+
$elements = explode(',', $host, 2);
12211221

1222-
$host = $elements[count($elements) - 1];
1222+
$host = $elements[0];
12231223
} elseif (!$host = $this->headers->get('HOST')) {
12241224
if (!$host = $this->server->get('SERVER_NAME')) {
12251225
$host = $this->server->get('SERVER_ADDR', '');

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ public function testTrustedProxies()
16361636
$request = Request::create('http://example.com/');
16371637
$request->server->set('REMOTE_ADDR', '3.3.3.3');
16381638
$request->headers->set('X_FORWARDED_FOR', '1.1.1.1, 2.2.2.2');
1639-
$request->headers->set('X_FORWARDED_HOST', 'foo.example.com, real.example.com:8080');
1639+
$request->headers->set('X_FORWARDED_HOST', 'foo.example.com:1234, real.example.com:8080');
16401640
$request->headers->set('X_FORWARDED_PROTO', 'https');
16411641
$request->headers->set('X_FORWARDED_PORT', 443);
16421642
$request->headers->set('X_MY_FOR', '3.3.3.3, 4.4.4.4');
@@ -1667,7 +1667,7 @@ public function testTrustedProxies()
16671667
// trusted proxy via setTrustedProxies()
16681668
Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2'));
16691669
$this->assertEquals('1.1.1.1', $request->getClientIp());
1670-
$this->assertEquals('real.example.com', $request->getHost());
1670+
$this->assertEquals('foo.example.com', $request->getHost());
16711671
$this->assertEquals(443, $request->getPort());
16721672
$this->assertTrue($request->isSecure());
16731673

src/Symfony/Component/Validator/Constraints/Composite.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public function __construct($options = null)
6767

6868
foreach ($nestedConstraints as $constraint) {
6969
if (!$constraint instanceof Constraint) {
70+
if (is_object($constraint)) {
71+
$constraint = get_class($constraint);
72+
}
73+
7074
throw new ConstraintDefinitionException(sprintf('The value %s is not an instance of Constraint in constraint %s', $constraint, get_class($this)));
7175
}
7276

src/Symfony/Component/Validator/Tests/Constraints/CompositeTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ public function testFailIfNoConstraint()
125125
));
126126
}
127127

128+
/**
129+
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
130+
*/
131+
public function testFailIfNoConstraintObject()
132+
{
133+
new ConcreteComposite(array(
134+
new NotNull(array('groups' => 'Default')),
135+
new \ArrayObject(),
136+
));
137+
}
138+
128139
/**
129140
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
130141
*/

0 commit comments

Comments
 (0)
0