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

Skip to content

Commit 11053c5

Browse files
Merge branch '2.8' into 3.4
* 2.8: fixed CS Changes for upcoming Travis' infra migration Doc fix: clarify isMethodCacheable() returns true only for GET & HEAD [DomCrawler] exclude fields inside "template" tags Use XLIFF source rather than resname when there's no target [DoctrineBridge] catch errors while converting to db values in data collector [DoctrineBridge] fix case sensitivity issue in RememberMe\DoctrineTokenProvider Indentation error [HttpFoundation] Fix trailing space for mime-type with parameters Use intersection type when referring to ParentNodeDefinitionInterface [BrowserKit] fixed BC Break for HTTP_HOST header; implemented same behaviour for HTTPS server parameter
2 parents 11fde69 + 316f96e commit 11053c5

File tree

15 files changed

+70
-17
lines changed

15 files changed

+70
-17
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
dist: trusty
4-
sudo: false
54

65
git:
76
depth: 2

src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Common\Persistence\ManagerRegistry;
1515
use Doctrine\DBAL\Logging\DebugStack;
16+
use Doctrine\DBAL\Types\ConversionException;
1617
use Doctrine\DBAL\Types\Type;
1718
use Symfony\Component\HttpFoundation\Request;
1819
use Symfony\Component\HttpFoundation\Response;
@@ -146,7 +147,14 @@ private function sanitizeQuery($connectionName, $query)
146147
}
147148
if ($type instanceof Type) {
148149
$query['types'][$j] = $type->getBindingType();
149-
$param = $type->convertToDatabaseValue($param, $this->registry->getConnection($connectionName)->getDatabasePlatform());
150+
try {
151+
$param = $type->convertToDatabaseValue($param, $this->registry->getConnection($connectionName)->getDatabasePlatform());
152+
} catch (\TypeError $e) {
153+
// Error thrown while processing params, query is not explainable.
154+
$query['explainable'] = false;
155+
} catch (ConversionException $e) {
156+
$query['explainable'] = false;
157+
}
150158
}
151159
}
152160

src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php

Lines changed: 3 additions & 2 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ public function __construct(Connection $conn)
5050
*/
5151
public function loadTokenBySeries($series)
5252
{
53-
$sql = 'SELECT class, username, value, lastUsed'
53+
// the alias for lastUsed works around case insensitivity in PostgreSQL
54+
$sql = 'SELECT class, username, value, lastUsed AS last_used'
5455
.' FROM rememberme_token WHERE series=:series';
5556
$paramValues = array('series' => $series);
5657
$paramTypes = array('series' => \PDO::PARAM_STR);
5758
$stmt = $this->conn->executeQuery($sql, $paramValues, $paramTypes);
5859
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
5960

6061
if ($row) {
61-
return new PersistentToken($row['class'], $row['username'], $series, $row['value'], new \DateTime($row['lastUsed']));
62+
return new PersistentToken($row['class'], $row['username'], $series, $row['value'], new \DateTime($row['last_used']));
6263
}
6364

6465
throw new TokenNotFoundException('No token found.');

src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Tests\DataCollector;
1313

1414
use Doctrine\DBAL\Platforms\MySqlPlatform;
15+
use Doctrine\DBAL\Version;
1516
use PHPUnit\Framework\TestCase;
1617
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector;
1718
use Symfony\Component\HttpFoundation\Request;
@@ -134,7 +135,7 @@ public function testSerialization($param, $types, $expected, $explainable)
134135

135136
public function paramProvider()
136137
{
137-
return array(
138+
$tests = array(
138139
array('some value', array(), 'some value', true),
139140
array(1, array(), 1, true),
140141
array(true, array(), true, true),
@@ -149,6 +150,13 @@ public function paramProvider()
149150
false,
150151
),
151152
);
153+
154+
if (version_compare(Version::VERSION, '2.6', '>=')) {
155+
$tests[] = array('this is not a date', array('date'), 'this is not a date', false);
156+
$tests[] = array(new \stdClass(), array('date'), 'Object(stdClass)', false);
157+
}
158+
159+
return $tests;
152160
}
153161

154162
private function createCollector($queries)

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,17 @@ public function request($method, $uri, array $parameters = array(), array $files
280280
++$this->redirectCount;
281281
}
282282

283+
$originalUri = $uri;
284+
283285
$uri = $this->getAbsoluteUri($uri);
284286

285287
$server = array_merge($this->server, $server);
286288

287-
if (isset($server['HTTPS'])) {
289+
if (!empty($server['HTTP_HOST']) && null === parse_url($originalUri, PHP_URL_HOST)) {
290+
$uri = preg_replace('{^(https?\://)'.preg_quote($this->extractHost($uri)).'}', '${1}'.$server['HTTP_HOST'], $uri);
291+
}
292+
293+
if (isset($server['HTTPS']) && null === parse_url($originalUri, PHP_URL_SCHEME)) {
288294
$uri = preg_replace('{^'.parse_url($uri, PHP_URL_SCHEME).'}', $server['HTTPS'] ? 'https' : 'http', $uri);
289295
}
290296

src/Symfony/Component/BrowserKit/Tests/ClientTest.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ public function testSetServerParameterInRequest()
679679
$this->assertEquals('', $client->getServerParameter('HTTP_HOST'));
680680
$this->assertEquals('Symfony BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
681681

682-
$this->assertEquals('http://www.example.com/https/www.example.com', $client->getRequest()->getUri());
682+
$this->assertEquals('https://www.example.com/https/www.example.com', $client->getRequest()->getUri());
683683

684684
$server = $client->getRequest()->getServer();
685685

@@ -693,7 +693,24 @@ public function testSetServerParameterInRequest()
693693
$this->assertEquals('new-server-key-value', $server['NEW_SERVER_KEY']);
694694

695695
$this->assertArrayHasKey('HTTPS', $server);
696-
$this->assertFalse($server['HTTPS']);
696+
$this->assertTrue($server['HTTPS']);
697+
}
698+
699+
public function testRequestWithRelativeUri()
700+
{
701+
$client = new TestClient();
702+
703+
$client->request('GET', '/', array(), array(), array(
704+
'HTTP_HOST' => 'testhost',
705+
'HTTPS' => true,
706+
));
707+
$this->assertEquals('https://testhost/', $client->getRequest()->getUri());
708+
709+
$client->request('GET', 'https://www.example.com/', array(), array(), array(
710+
'HTTP_HOST' => 'testhost',
711+
'HTTPS' => false,
712+
));
713+
$this->assertEquals('https://www.example.com/', $client->getRequest()->getUri());
697714
}
698715

699716
public function testInternalRequest()

src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function variableNode($name)
133133
/**
134134
* Returns the parent node.
135135
*
136-
* @return ParentNodeDefinitionInterface|NodeDefinition The parent node
136+
* @return NodeDefinition&ParentNodeDefinitionInterface The parent node
137137
*/
138138
public function end()
139139
{

src/Symfony/Component/DomCrawler/Form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,14 @@ private function initialize()
443443
// corresponding elements are either descendants or have a matching HTML5 form attribute
444444
$formId = Crawler::xpathLiteral($this->node->getAttribute('id'));
445445

446-
$fieldNodes = $xpath->query(sprintf('descendant::input[@form=%s] | descendant::button[@form=%1$s] | descendant::textarea[@form=%1$s] | descendant::select[@form=%1$s] | //form[@id=%1$s]//input[not(@form)] | //form[@id=%1$s]//button[not(@form)] | //form[@id=%1$s]//textarea[not(@form)] | //form[@id=%1$s]//select[not(@form)]', $formId));
446+
$fieldNodes = $xpath->query(sprintf('( descendant::input[@form=%s] | descendant::button[@form=%1$s] | descendant::textarea[@form=%1$s] | descendant::select[@form=%1$s] | //form[@id=%1$s]//input[not(@form)] | //form[@id=%1$s]//button[not(@form)] | //form[@id=%1$s]//textarea[not(@form)] | //form[@id=%1$s]//select[not(@form)] )[not(ancestor::template)]', $formId));
447447
foreach ($fieldNodes as $node) {
448448
$this->addField($node);
449449
}
450450
} else {
451451
// do the xpath query with $this->node as the context node, to only find descendant elements
452452
// however, descendant elements with form attribute are not part of this form
453-
$fieldNodes = $xpath->query('descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)]', $this->node);
453+
$fieldNodes = $xpath->query('( descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)] )[not(ancestor::template)]', $this->node);
454454
foreach ($fieldNodes as $node) {
455455
$this->addField($node);
456456
}

src/Symfony/Component/DomCrawler/Tests/FormTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ public function testGetValues()
400400

401401
$form = $this->createForm('<form><input type="text" name="foo" value="foo" disabled="disabled" /><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
402402
$this->assertEquals(array('bar' => 'bar'), $form->getValues(), '->getValues() does not include disabled fields');
403+
404+
$form = $this->createForm('<form><template><input type="text" name="foo" value="foo" /></template><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
405+
$this->assertEquals(array('bar' => 'bar'), $form->getValues(), '->getValues() does not include template fields');
406+
$this->assertFalse($form->has('foo'));
403407
}
404408

405409
public function testSetValues()
@@ -450,6 +454,10 @@ public function testGetFiles()
450454

451455
$form = $this->createForm('<form method="post"><input type="file" name="foo[bar]" disabled="disabled" /><input type="submit" /></form>');
452456
$this->assertEquals(array(), $form->getFiles(), '->getFiles() does not include disabled file fields');
457+
458+
$form = $this->createForm('<form method="post"><template><input type="file" name="foo"/></template><input type="text" name="bar" value="bar"/><input type="submit"/></form>');
459+
$this->assertEquals(array(), $form->getFiles(), '->getFiles() does not include template D3A8 file fields');
460+
$this->assertFalse($form->has('foo'));
453461
}
454462

455463
public function testGetPhpFiles()
@@ -869,7 +877,7 @@ protected function getFormFieldMock($name, $value = null)
869877
protected function createForm($form, $method = null, $currentUri = null)
870878
{
871879
$dom = new \DOMDocument();
872-
$dom->loadHTML('<html>'.$form.'</html>');
880+
@$dom->loadHTML('<html>'.$form.'</html>');
873881

874882
$xPath = new \DOMXPath($dom);
875883
$nodes = $xPath->query('//input | //button');

src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ public static function getSubscribedEvents()
426426
return array(
427427
'pre.foo' => array('preFoo', 10),
428428
'post.foo' => array('postFoo'),
429-
);
429+
);
430430
}
431431
}
432432

0 commit comments

Comments
 (0)
0