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
This commit is contained in:
commit
3e47e9ca59
@ -612,7 +612,7 @@ class Table
|
|||||||
$lengths[] = $this->getCellWidth($row, $column);
|
$lengths[] = $this->getCellWidth($row, $column);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->effectiveColumnWidths[$column] = max($lengths) + \strlen($this->style->getCellRowContentFormat()) - 2;
|
$this->effectiveColumnWidths[$column] = max($lengths) + Helper::strlen($this->style->getCellRowContentFormat()) - 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -623,7 +623,7 @@ class Table
|
|||||||
*/
|
*/
|
||||||
private function getColumnSeparatorWidth()
|
private function getColumnSeparatorWidth()
|
||||||
{
|
{
|
||||||
return \strlen(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar()));
|
return Helper::strlen(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -824,6 +824,42 @@ TABLE;
|
|||||||
Table::getStyleDefinition('absent');
|
Table::getStyleDefinition('absent');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testBoxedStyleWithColspan()
|
||||||
|
{
|
||||||
|
$boxed = new TableStyle();
|
||||||
|
$boxed
|
||||||
|
->setHorizontalBorderChar('─')
|
||||||
|
->setVerticalBorderChar('│')
|
||||||
|
->setCrossingChar('┼')
|
||||||
|
;
|
||||||
|
|
||||||
|
$table = new Table($output = $this->getOutputStream());
|
||||||
|
$table->setStyle($boxed);
|
||||||
|
$table
|
||||||
|
->setHeaders(array('ISBN', 'Title', 'Author'))
|
||||||
|
->setRows(array(
|
||||||
|
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
|
||||||
|
new TableSeparator(),
|
||||||
|
array(new TableCell('This value spans 3 columns.', array('colspan' => 3))),
|
||||||
|
))
|
||||||
|
;
|
||||||
|
$table->render();
|
||||||
|
|
||||||
|
$expected =
|
||||||
|
<<<TABLE
|
||||||
|
┼───────────────┼───────────────┼─────────────────┼
|
||||||
|
│ ISBN │ Title │ Author │
|
||||||
|
┼───────────────┼───────────────┼─────────────────┼
|
||||||
|
│ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri │
|
||||||
|
┼───────────────┼───────────────┼─────────────────┼
|
||||||
|
│ This value spans 3 columns. │
|
||||||
|
┼───────────────┼───────────────┼─────────────────┼
|
||||||
|
|
||||||
|
TABLE;
|
||||||
|
|
||||||
|
$this->assertSame($expected, $this->getOutputContent($output));
|
||||||
|
}
|
||||||
|
|
||||||
protected function getOutputStream($decorated = false)
|
protected function getOutputStream($decorated = false)
|
||||||
{
|
{
|
||||||
return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, $decorated);
|
return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, $decorated);
|
||||||
|
@ -68,6 +68,10 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})T\d{2}:\d{2}(?::\d{2})?(?:\.\d)?(?:Z|(?:(?:\+|-)\d{2}:\d{2}))$/', $rfc3339, $matches)) {
|
||||||
|
throw new TransformationFailedException(sprintf('The date "%s" is not a valid date.', $rfc3339));
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$dateTime = new \DateTime($rfc3339);
|
$dateTime = new \DateTime($rfc3339);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -78,10 +82,8 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
|
|||||||
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
|
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preg_match('/(\d{4})-(\d{2})-(\d{2})/', $rfc3339, $matches)) {
|
if (!checkdate($matches[2], $matches[3], $matches[1])) {
|
||||||
if (!checkdate($matches[2], $matches[3], $matches[1])) {
|
throw new TransformationFailedException(sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
|
||||||
throw new TransformationFailedException(sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $dateTime;
|
return $dateTime;
|
||||||
|
@ -133,12 +133,25 @@ class DateTimeToRfc3339TransformerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @dataProvider invalidDateStringProvider
|
||||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testReverseTransformExpectsValidDateString()
|
public function testReverseTransformExpectsValidDateString($date)
|
||||||
{
|
{
|
||||||
$transformer = new DateTimeToRfc3339Transformer('UTC', 'UTC');
|
$transformer = new DateTimeToRfc3339Transformer('UTC', 'UTC');
|
||||||
|
|
||||||
$transformer->reverseTransform('2010-2010-2010');
|
$transformer->reverseTransform($date);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function invalidDateStringProvider()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'invalid month' => array('2010-2010-01'),
|
||||||
|
'invalid day' => array('2010-10-2010'),
|
||||||
|
'no date' => array('x'),
|
||||||
|
'cookie format' => array('Saturday, 01-May-2010 04:05:00 Z'),
|
||||||
|
'RFC 822 format' => array('Sat, 01 May 10 04:05:00 +0000'),
|
||||||
|
'RSS format' => array('Sat, 01 May 2010 04:05:00 +0000'),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -516,7 +516,7 @@ class NumberFormatter
|
|||||||
$groupSep = $this->getAttribute(self::GROUPING_USED) ? ',' : '';
|
$groupSep = $this->getAttribute(self::GROUPING_USED) ? ',' : '';
|
||||||
|
|
||||||
// Any string before the numeric value causes error in the parsing
|
// Any string before the numeric value causes error in the parsing
|
||||||
if (preg_match("/^-?(?:\.\d++|([\d{$groupSep}]++)(?:\.\d++)?)/", $value, $matches)) {
|
if (preg_match("/^-?(?:\.\d++|([\d{$groupSep}]++)(?:\.\d*+)?)/", $value, $matches)) {
|
||||||
$value = $matches[0];
|
$value = $matches[0];
|
||||||
$position = \strlen($value);
|
$position = \strlen($value);
|
||||||
if ($error = $groupSep && isset($matches[1]) && !preg_match('/^\d{1,3}+(?:(?:,\d{3})++|\d*+)$/', $matches[1])) {
|
if ($error = $groupSep && isset($matches[1]) && !preg_match('/^\d{1,3}+(?:(?:,\d{3})++|\d*+)$/', $matches[1])) {
|
||||||
|
@ -654,6 +654,7 @@ abstract class AbstractNumberFormatterTest extends TestCase
|
|||||||
array('-123,4567', false, '->parse() does not parse when invalid grouping used.', 9),
|
array('-123,4567', false, '->parse() does not parse when invalid grouping used.', 9),
|
||||||
array('-123,,456', false, '->parse() does not parse when invalid grouping used.', 4),
|
array('-123,,456', false, '->parse() does not parse when invalid grouping used.', 4),
|
||||||
array('-123,,456', -123.0, '->parse() parses when grouping is disabled.', 4, false),
|
array('-123,,456', -123.0, '->parse() parses when grouping is disabled.', 4, false),
|
||||||
|
array('239.', 239.0, '->parse() parses when string ends with decimal separator.', 4, false),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user