Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e47775

Browse files
Merge branch '3.4' into 4.1
* 3.4: [Debug] Fix false-positive "MicroKernelTrait::loadRoutes()" method is considered internal" [Console] Fixed boxed table style with colspan parse numbers terminated with decimal separator fail reverse transforming invalid RFC 3339 dates
2 parents 76cf0ca + 9bc774c commit 0e47775

File tree

9 files changed

+273
-165
lines changed

9 files changed

+273
-165
lines changed

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,13 +656,13 @@ private function calculateColumnsWidth(iterable $rows)
656656
$lengths[] = $this->getCellWidth($row, $column);
657657
}
658658

659-
$this->effectiveColumnWidths[$column] = max($lengths) + \strlen($this->style->getCellRowContentFormat()) - 2;
659+
$this->effectiveColumnWidths[$column] = max($lengths) + Helper::strlen($this->style->getCellRowContentFormat()) - 2;
660660
}
661661
}
662662

663663
private function getColumnSeparatorWidth(): int
664664
{
665-
return \strlen(sprintf($this->style->getBorderFormat(), $this->style->getBorderChars()[3]));
665+
return Helper::strlen(sprintf($this->style->getBorderFormat(), $this->style->getBorderChars()[3]));
666666
}
667667

668668
private function getCellWidth(array $row, int $column): int

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,42 @@ public function testGetStyleDefinition()
974974
Table::getStyleDefinition('absent');
975975
}
976976

977+
public function testBoxedStyleWithColspan()
978+
{
979+
$boxed = new TableStyle();
980+
$boxed
981+
->setHorizontalBorderChars('')
982+
->setVerticalBorderChars('')
983+
->setCrossingChars('', '', '', '', '', '', '', '', '')
984+
;
985+
986+
$table = new Table($output = $this->getOutputStream());
987+
$table->setStyle($boxed);
988+
$table
989+
->setHeaders(array('ISBN', 'Title', 'Author'))
990+
->setRows(array(
991+
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
992+
new TableSeparator(),
993+
array(new TableCell('This value spans 3 columns.', array('colspan' => 3))),
994+
))
995+
;
996+
$table->render();
997+
998+
$expected =
999+
<<<TABLE
1000+
┌───────────────┬───────────────┬─────────────────┐
1001+
│ ISBN │ Title │ Author │
1002+
├───────────────┼───────────────┼─────────────────┤
1003+
│ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri │
1004+
├───────────────┼───────────────┼─────────────────┤
1005+
│ This value spans 3 columns. │
1006+
└───────────────┴───────────────┴─────────────────┘
1007+
1008+
TABLE;
1009+
1010+
$this->assertSame($expected, $this->getOutputContent($output));
1011+
}
1012+
9771013
protected function getOutputStream($decorated = false)
9781014
{
9791015
return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, $decorated);

src/Symfony/Component/Debug/DebugClassLoader.php

Lines changed: 181 additions & 154 deletions
Large diffs are not rendered by default.

src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,26 @@ class_exists('Test\\'.__NAMESPACE__.'\\ExtendsInternals', true);
266266
restore_error_handler();
267267

268268
$this->assertSame($deprecations, array(
269-
'The "Symfony\Component\Debug\Tests\Fixtures\InternalClass" class is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternalsParent".',
270269
'The "Symfony\Component\Debug\Tests\Fixtures\InternalInterface" interface is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternalsParent".',
270+
'The "Symfony\Component\Debug\Tests\Fixtures\InternalClass" class is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternalsParent".',
271271
'The "Symfony\Component\Debug\Tests\Fixtures\InternalTrait" trait is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".',
272-
'The "Symfony\Component\Debug\Tests\Fixtures\InternalTrait2::internalMethod()" method is considered internal. It may change without further notice. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".',
272+
'The "Symfony\Component\Debug\Tests\Fixtures\InternalClass::internalMethod()" method is considered internal. It may change without further notice. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".',
273273
));
274274
}
275+
276+
public function testUseTraitWithInternalMethod()
277+
{
278+
$deprecations = array();
279+
set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; });
280+
$e = error_reporting(E_USER_DEPRECATED);
281+
282+
class_exists('Test\\'.__NAMESPACE__.'\\UseTraitWithInternalMethod', true);
283+
284+
error_reporting($e);
285+
restore_error_handler();
286+
287+
$this->assertSame(array(), $deprecations);
288+
}
275289
}
276290

277291
class ClassLoader
@@ -325,6 +339,8 @@ public function internalMethod() { }
325339
}');
326340
} elseif ('Test\\'.__NAMESPACE__.'\ExtendsInternalsParent' === $class) {
327341
eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsInternalsParent extends \\'.__NAMESPACE__.'\Fixtures\InternalClass implements \\'.__NAMESPACE__.'\Fixtures\InternalInterface { }');
342+
} elseif ('Test\\'.__NAMESPACE__.'\UseTraitWithInternalMethod' === $class) {
343+
eval('namespace Test\\'.__NAMESPACE__.'; class UseTraitWithInternalMethod { use \\'.__NAMESPACE__.'\Fixtures\TraitWithInternalMethod; }');
328344
}
329345
}
330346
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Symfony\Component\Debug\Tests\Fixtures;
4+
5+
trait TraitWithInternalMethod
6+
{
7+
/**
8+
* @internal
9+
*/
10+
public function foo()
11+
{
12+
}
13+
}

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public function reverseTransform($rfc3339)
6868
return;
6969
}
7070

71+
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})T\d{2}:\d{2}(?::\d{2})?(?:\.\d)?(?:Z|(?:(?:\+|-)\d{2}:\d{2}))$/', $rfc3339, $matches)) {
72+
throw new TransformationFailedException(sprintf('The date "%s" is not a valid date.', $rfc3339));
73+
}
74+
7175
try {
7276
$dateTime = new \DateTime($rfc3339);
7377
} catch (\Exception $e) {
@@ -78,10 +82,8 @@ public function reverseTransform($rfc3339)
7882
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
7983
}
8084

81-
if (preg_match('/(\d{4})-(\d{2})-(\d{2})/', $rfc3339, $matches)) {
82-
if (!checkdate($matches[2], $matches[3], $matches[1])) {
83-
throw new TransformationFailedException(sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
84-
}
85+
if (!checkdate($matches[2], $matches[3], $matches[1])) {
86+
throw new TransformationFailedException(sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
8587
}
8688

8789
return $dateTime;

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToRfc3339TransformerTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,25 @@ public function testReverseTransformWithNonExistingDate()
133133
}
134134

135135
/**
136+
* @dataProvider invalidDateStringProvider
136137
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
137138
*/
138-
public function testReverseTransformExpectsValidDateString()
139+
public function testReverseTransformExpectsValidDateString($date)
139140
{
140141
$transformer = new DateTimeToRfc3339Transformer('UTC', 'UTC');
141142

142-
$transformer->reverseTransform('2010-2010-2010');
143+
$transformer->reverseTransform($date);
144+
}
145+
146+
public function invalidDateStringProvider()
147+
{
148+
return array(
149+
'invalid month' => array('2010-2010-01'),
150+
'invalid day' => array('2010-10-2010'),
151+
'no date' => array('x'),
152+
'cookie format' => array('Saturday, 01-May-2010 04:05:00 Z'),
153+
'RFC 822 format' => array('Sat, 01 May 10 04:05:00 +0000'),
154+
'RSS format' => array('Sat, 01 May 2010 04:05:00 +0000'),
155+
);
143156
}
144157
}

src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ public function parse($value, $type = self::TYPE_DOUBLE, &$position = 0)
516516
$groupSep = $this->getAttribute(self::GROUPING_USED) ? ',' : '';
517517

518518
// Any string before the numeric value causes error in the parsing
519-
if (preg_match("/^-?(?:\.\d++|([\d{$groupSep}]++)(?:\.\d++)?)/", $value, $matches)) {
519+
if (preg_match("/^-?(?:\.\d++|([\d{$groupSep}]++)(?:\.\d*+)?)/", $value, $matches)) {
520520
$value = $matches[0];
521521
$position = \strlen($value);
522522
if ($error = $groupSep && isset($matches[1]) && !preg_match('/^\d{1,3}+(?:(?:,\d{3})++|\d*+)$/', $matches[1])) {

src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ public function parseProvider()
654654
array('-123,4567', false, '->parse() does not parse when invalid grouping used.', 9),
655655
array('-123,,456', false, '->parse() does not parse when invalid grouping used.', 4),
656656
array('-123,,456', -123.0, '->parse() parses when grouping is disabled.', 4, false),
657+
array('239.', 239.0, '->parse() parses when string ends with decimal separator.', 4, false),
657658
);
658659
}
659660

0 commit comments

Comments
 (0)