Merge branch '2.3' into 2.7

This commit is contained in:
Tobias Schultze 2016-01-04 15:49:16 +01:00
commit fff265d451
4 changed files with 76 additions and 17 deletions

View File

@ -29,6 +29,7 @@ class DateTimeTypeTest extends TestCase
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'date_widget' => 'choice',
'years' => array(2010),
'time_widget' => 'choice',
'input' => 'datetime',
));
@ -57,6 +58,7 @@ class DateTimeTypeTest extends TestCase
'view_timezone' => 'UTC',
'input' => 'string',
'date_widget' => 'choice',
'years' => array(2010),
'time_widget' => 'choice',
));
@ -82,6 +84,7 @@ class DateTimeTypeTest extends TestCase
'view_timezone' => 'UTC',
'input' => 'timestamp',
'date_widget' => 'choice',
'years' => array(2010),
'time_widget' => 'choice',
));
@ -108,12 +111,13 @@ class DateTimeTypeTest extends TestCase
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'date_widget' => 'choice',
'years' => array(2010),
'time_widget' => 'choice',
'input' => 'datetime',
'with_minutes' => false,
));
$form->setData(new \DateTime('2010-06-02 03:04:05 UTC'));
$form->setData(new \DateTime());
$input = array(
'date' => array(
@ -137,12 +141,13 @@ class DateTimeTypeTest extends TestCase
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'date_widget' => 'choice',
'years' => array(2010),
'time_widget' => 'choice',
'input' => 'datetime',
'with_seconds' => true,
));
$form->setData(new \DateTime('2010-06-02 03:04:05 UTC'));
$form->setData(new \DateTime());
$input = array(
'date' => array(
@ -168,6 +173,7 @@ class DateTimeTypeTest extends TestCase
'model_timezone' => 'America/New_York',
'view_timezone' => 'Pacific/Tahiti',
'date_widget' => 'choice',
'years' => array(2010),
'time_widget' => 'choice',
'input' => 'string',
'with_seconds' => true,

View File

@ -187,6 +187,7 @@ class DateTypeTest extends TestCase
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'widget' => 'choice',
'years' => array(2010),
));
$text = array(

View File

@ -343,7 +343,11 @@ class Parser
private function getNextEmbedBlock($indentation = null, $inSequence = false)
{
$oldLineIndentation = $this->getCurrentLineIndentation();
$insideBlockScalar = $this->isBlockScalarHeader();
$blockScalarIndentations = array();
if ($this->isBlockScalarHeader()) {
$blockScalarIndentations[] = $this->getCurrentLineIndentation();
}
if (!$this->moveToNextLine()) {
return;
@ -380,8 +384,8 @@ class Parser
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem();
if (!$insideBlockScalar) {
$insideBlockScalar = $this->isBlockScalarHeader();
if (empty($blockScalarIndentations) && $this->isBlockScalarHeader()) {
$blockScalarIndentations[] = $this->getCurrentLineIndentation();
}
$previousLineIndentation = $this->getCurrentLineIndentation();
@ -389,8 +393,17 @@ class Parser
while ($this->moveToNextLine()) {
$indent = $this->getCurrentLineIndentation();
if (!$insideBlockScalar && $indent === $previousLineIndentation) {
$insideBlockScalar = $this->isBlockScalarHeader();
// terminate all block scalars that are more indented than the current line
if (!empty($blockScalarIndentations) && $indent < $previousLineIndentation && trim($this->currentLine) !== '') {
foreach ($blockScalarIndentations as $key => $blockScalarIndentation) {
if ($blockScalarIndentation >= $this->getCurrentLineIndentation()) {
unset($blockScalarIndentations[$key]);
}
}
}
if (empty($blockScalarIndentations) && !$this->isCurrentLineComment() && $this->isBlockScalarHeader()) {
$blockScalarIndentations[] = $this->getCurrentLineIndentation();
}
$previousLineIndentation = $indent;
@ -406,7 +419,7 @@ class Parser
}
// we ignore "comment" lines only when we are not inside a scalar block
if (!$insideBlockScalar && $this->isCurrentLineComment()) {
if (empty($blockScalarIndentations) && $this->isCurrentLineComment()) {
continue;
}
@ -564,7 +577,7 @@ class Parser
$previousLineIndented = false;
$previousLineBlank = false;
for ($i = 0; $i < count($blockLines); $i++) {
for ($i = 0; $i < count($blockLines); ++$i) {
if ('' === $blockLines[$i]) {
$text .= "\n";
$previousLineIndented = false;
@ -659,7 +672,7 @@ class Parser
//checking explicitly the first char of the trim is faster than loops or strpos
$ltrimmedLine = ltrim($this->currentLine, ' ');
return $ltrimmedLine[0] === '#';
return '' !== $ltrimmedLine && $ltrimmedLine[0] === '#';
}
/**

View File

@ -816,7 +816,9 @@ EOF;
public function getCommentLikeStringInScalarBlockData()
{
$yaml1 = <<<'EOT'
$tests = array();
$yaml = <<<'EOT'
pages:
-
title: some title
@ -831,7 +833,7 @@ pages:
footer # comment3
EOT;
$expected1 = array(
$expected = array(
'pages' => array(
array(
'title' => 'some title',
@ -850,8 +852,9 @@ EOT
),
),
);
$tests[] = array($yaml, $expected);
$yaml2 = <<<'EOT'
$yaml = <<<'EOT'
test: |
foo
# bar
@ -866,7 +869,7 @@ collection:
# bar
baz
EOT;
$expected2 = array(
$expected = array(
'test' => <<<'EOT'
foo
# bar
@ -893,11 +896,47 @@ EOT
),
),
);
$tests[] = array($yaml, $expected);
return array(
array($yaml1, $expected1),
array($yaml2, $expected2),
$yaml = <<<EOT
foo:
bar:
scalar-block: >
line1
line2>
baz:
# comment
foobar: ~
EOT;
$expected = array(
'foo' => array(
'bar' => array(
'scalar-block' => 'line1 line2>',
),
'baz' => array(
'foobar' => null,
),
),
);
$tests[] = array($yaml, $expected);
$yaml = <<<'EOT'
a:
b: hello
# c: |
# first row
# second row
d: hello
EOT;
$expected = array(
'a' => array(
'b' => 'hello',
'd' => 'hello',
),
);
$tests[] = array($yaml, $expected);
return $tests;
}
public function testBlankLinesAreParsedAsNewLinesInFoldedBlocks()