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

Skip to content

Commit 3e47e9c

Browse files
Merge branch '2.8' into 3.4
* 2.8: [Console] Fixed boxed table style with colspan parse numbers terminated with decimal separator fail reverse transforming invalid RFC 3339 dates
2 parents 0218507 + 57a3413 commit 3e47e9c

File tree

6 files changed

+61
-9
lines changed
  • src/Symfony/Component
    • Console
      • Helper
  • Tests/Helper
  • Form
  • Intl
  • 6 files changed

    +61
    -9
    lines changed

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

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -612,7 +612,7 @@ private function calculateColumnsWidth(array $rows)
    612612
    $lengths[] = $this->getCellWidth($row, $column);
    613613
    }
    614614

    615-
    $this->effectiveColumnWidths[$column] = max($lengths) + \strlen($this->style->getCellRowContentFormat()) - 2;
    615+
    $this->effectiveColumnWidths[$column] = max($lengths) + Helper::strlen($this->style->getCellRowContentFormat()) - 2;
    616616
    }
    617617
    }
    618618

    @@ -623,7 +623,7 @@ private function calculateColumnsWidth(array $rows)
    623623
    */
    624624
    private function getColumnSeparatorWidth()
    625625
    {
    626-
    return \strlen(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar()));
    626+
    return Helper::strlen(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar()));
    627627
    }
    628628

    629629
    /**

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

    Lines changed: 36 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -824,6 +824,42 @@ public function testGetStyleDefinition()
    824824
    Table::getStyleDefinition('absent');
    825825
    }
    826826

    827+
    public function testBoxedStyleWithColspan()
    828+
    {
    829+
    $boxed = new TableStyle();
    830+
    $boxed
    831+
    ->setHorizontalBorderChar('')
    832+
    ->setVerticalBorderChar('')
    833+
    ->setCrossingChar('')
    834+
    ;
    835+
    836+
    $table = new Table($output = $this->getOutputStream());
    837+
    $table->setStyle($boxed);
    838+
    $table
    839+
    ->setHeaders(array('ISBN', 'Title', 'Author'))
    840+
    ->setRows(array(
    841+
    array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
    842+
    new TableSeparator(),
    843+
    array(new TableCell('This value spans 3 columns.', array('colspan' => 3))),
    844+
    ))
    845+
    ;
    846+
    $table->render();
    847+
    848+
    $expected =
    849+
    <<<TABLE
    850+
    ┼───────────────┼───────────────┼─────────────────┼
    851+
    │ ISBN │ Title │ Author │
    852+
    ┼───────────────┼───────────────┼─────────────────┼
    853+
    │ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri │
    854+
    ┼───────────────┼───────────────┼─────────────────┼
    855+
    │ This value spans 3 columns. │
    856+
    ┼───────────────┼───────────────┼─────────────────┼
    857+
    858+
    TABLE;
    859+
    860+
    $this->assertSame($expected, $this->getOutputContent($output));
    861+
    }
    862+
    827863
    protected function getOutputStream($decorated = false)
    828864
    {
    829865
    return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, $decorated);

    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)
    0