Skip to content

Commit 3686ed6

Browse files
committed
Merge branch '2.7' into 2.8
2 parents 67ccb2d + fff265d commit 3686ed6

File tree

4 files changed

+76
-17
lines changed

4 files changed

+76
-17
lines changed

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function testSubmitDateTime()
3939
'model_timezone' => 'UTC',
4040
'view_timezone' => 'UTC',
4141
'date_widget' => 'choice',
42+
'years' => array(2010),
4243
'time_widget' => 'choice',
4344
'input' => 'datetime',
4445
));
@@ -67,6 +68,7 @@ public function testSubmitString()
6768
'view_timezone' => 'UTC',
6869
'input' => 'string',
6970
'date_widget' => 'choice',
71+
'years' => array(2010),
7072
'time_widget' => 'choice',
7173
));
7274

@@ -92,6 +94,7 @@ public function testSubmitTimestamp()
9294
'view_timezone' => 'UTC',
9395
'input' => 'timestamp',
9496
'date_widget' => 'choice',
97+
'years' => array(2010),
9598
'time_widget' => 'choice',
9699
));
97100

@@ -118,12 +121,13 @@ public function testSubmitWithoutMinutes()
118121
'model_timezone' => 'UTC',
119122
'view_timezone' => 'UTC',
120123
'date_widget' => 'choice',
124+
'years' => array(2010),
121125
'time_widget' => 'choice',
122126
'input' => 'datetime',
123127
'with_minutes' => false,
124128
));
125129

126-
$form->setData(new \DateTime('2010-06-02 03:04:05 UTC'));
130+
$form->setData(new \DateTime());
127131

128132
$input = array(
129133
'date' => array(
@@ -147,12 +151,13 @@ public function testSubmitWithSeconds()
147151
'model_timezone' => 'UTC',
148152
'view_timezone' => 'UTC',
149153
'date_widget' => 'choice',
154+
'years' => array(2010),
150155
'time_widget' => 'choice',
151156
'input' => 'datetime',
152157
'with_seconds' => true,
153158
));
154159

155-
$form->setData(new \DateTime('2010-06-02 03:04:05 UTC'));
160+
$form->setData(new \DateTime());
156161

157162
$input = array(
158163
'date' => array(
@@ -178,6 +183,7 @@ public function testSubmitDifferentTimezones()
178183
'model_timezone' => 'America/New_York',
179184
'view_timezone' => 'Pacific/Tahiti',
180185
'date_widget' => 'choice',
186+
'years' => array(2010),
181187
'time_widget' => 'choice',
182188
'input' => 'string',
183189
'with_seconds' => true,

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public function testSubmitFromChoice()
197197
'model_timezone' => 'UTC',
198198
'view_timezone' => 'UTC',
199199
'widget' => 'choice',
200+
'years' => array(2010),
200201
));
201202

202203
$text = array(

src/Symfony/Component/Yaml/Parser.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,11 @@ private function getCurrentLineIndentation()
343343
private function getNextEmbedBlock($indentation = null, $inSequence = false)
344344
{
345345
$oldLineIndentation = $this->getCurrentLineIndentation();
346-
$insideBlockScalar = $this->isBlockScalarHeader();
346+
$blockScalarIndentations = array();
347+
348+
if ($this->isBlockScalarHeader()) {
349+
$blockScalarIndentations[] = $this->getCurrentLineIndentation();
350+
}
347351

348352
if (!$this->moveToNextLine()) {
349353
return;
@@ -380,17 +384,26 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
380384

381385
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem();
382386

383-
if (!$insideBlockScalar) {
384-
$insideBlockScalar = $this->isBlockScalarHeader();
387+
if (empty($blockScalarIndentations) && $this->isBlockScalarHeader()) {
388+
$blockScalarIndentations[] = $this->getCurrentLineIndentation();
385389
}
386390

387391
$previousLineIndentation = $this->getCurrentLineIndentation();
388392

389393
while ($this->moveToNextLine()) {
390394
$indent = $this->getCurrentLineIndentation();
391395

392-
if (!$insideBlockScalar && $indent === $previousLineIndentation) {
393-
$insideBlockScalar = $this->isBlockScalarHeader();
396+
// terminate all block scalars that are more indented than the current line
397+
if (!empty($blockScalarIndentations) && $indent < $previousLineIndentation && trim($this->currentLine) !== '') {
398+
foreach ($blockScalarIndentations as $key => $blockScalarIndentation) {
399+
if ($blockScalarIndentation >= $this->getCurrentLineIndentation()) {
400+
unset($blockScalarIndentations[$key]);
401+
}
402+
}
403+
}
404+
405+
if (empty($blockScalarIndentations) && !$this->isCurrentLineComment() && $this->isBlockScalarHeader()) {
406+
$blockScalarIndentations[] = $this->getCurrentLineIndentation();
394407
}
395408

396409
$previousLineIndentation = $indent;
@@ -406,7 +419,7 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
406419
}
407420

408421
// we ignore "comment" lines only when we are not inside a scalar block
409-
if (!$insideBlockScalar && $this->isCurrentLineComment()) {
422+
if (empty($blockScalarIndentations) && $this->isCurrentLineComment()) {
410423
continue;
411424
}
412425

@@ -574,7 +587,7 @@ private function parseBlockScalar($style, $chomping = '', $indentation = 0)
574587
$previousLineIndented = false;
575588
$previousLineBlank = false;
576589

577-
for ($i = 0; $i < count($blockLines); $i++) {
590+
for ($i = 0; $i < count($blockLines); ++$i) {
578591
if ('' === $blockLines[$i]) {
579592
$text .= "\n";
580593
$previousLineIndented = false;
@@ -669,7 +682,7 @@ private function isCurrentLineComment()
669682
//checking explicitly the first char of the trim is faster than loops or strpos
670683
$ltrimmedLine = ltrim($this->currentLine, ' ');
671684

672-
return $ltrimmedLine[0] === '#';
685+
return '' !== $ltrimmedLine && $ltrimmedLine[0] === '#';
673686
}
674687

675688
/**

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,9 @@ public function testCommentLikeStringsAreNotStrippedInBlockScalars($yaml, $expec
851851

852852
public function getCommentLikeStringInScalarBlockData()
853853
{
854-
$yaml1 = <<<'EOT'
854+
$tests = array();
855+
856+
$yaml = <<<'EOT'
855857
pages:
856858
-
857859
title: some title
@@ -866,7 +868,7 @@ public function getCommentLikeStringInScalarBlockData()
866868
867869
footer # comment3
868870
EOT;
869-
$expected1 = array(
871+
$expected = array(
870872
'pages' => array(
871873
array(
872874
'title' => 'some title',
@@ -885,8 +887,9 @@ public function getCommentLikeStringInScalarBlockData()
885887
),
886888
),
887889
);
890+
$tests[] = array($yaml, $expected);
888891

889-
$yaml2 = <<<'EOT'
892+
$yaml = <<<'EOT'
890893
test: |
891894
foo
892895
# bar
@@ -901,7 +904,7 @@ public function getCommentLikeStringInScalarBlockData()
901904
# bar
902905
baz
903906
EOT;
904-
$expected2 = array(
907+
$expected = array(
905908
'test' => <<<'EOT'
906909
foo
907910
# bar
@@ -928,11 +931,47 @@ public function getCommentLikeStringInScalarBlockData()
928931
),
929932
),
930933
);
934+
$tests[] = array($yaml, $expected);
931935

932-
return array(
933-
array($yaml1, $expected1),
934-
array($yaml2, $expected2),
936+
$yaml = <<<EOT
937+
foo:
938+
bar:
939+
scalar-block: >
940+
line1
941+
line2>
942+
baz:
943+
# comment
944+
foobar: ~
945+
EOT;
946+
$expected = array(
947+
'foo' => array(
948+
'bar' => array(
949+
'scalar-block' => 'line1 line2>',
950+
),
951+
'baz' => array(
952+
'foobar' => null,
953+
),
954+
),
935955
);
956+
$tests[] = array($yaml, $expected);
957+
958+
$yaml = <<<'EOT'
959+
a:
960+
b: hello
961+
# c: |
962+
# first row
963+
# second row
964+
d: hello
965+
EOT;
966+
$expected = array(
967+
'a' => array(
968+
'b' => 'hello',
969+
'd' => 'hello',
970+
),
971+
);
972+
$tests[] = array($yaml, $expected);
973+
974+
return $tests;
936975
}
937976

938977
public function testBlankLinesAreParsedAsNewLinesInFoldedBlocks()

0 commit comments

Comments
 (0)