8000 Merge branch '2.3' into 2.7 · symfony/symfony@fff265d · GitHub
[go: up one dir, main page]

Skip to content

Commit fff265d

Browse files
committed
Merge branch '2.3' into 2.7
2 parents 6dbef8c + eeaa4dc commit fff265d

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
@@ -29,6 +29,7 @@ public function testSubmitDateTime()
2929
'model_timezone' => 'UTC',
3030
'view_timezone' => 'UTC',
3131
'date_widget' => 'choice',
32+
'years' => array(2010),
3233
'time_widget' => 'choice',
3334
'input' => 'datetime',
3435
));
@@ -57,6 +58,7 @@ public function testSubmitString()
5758
'view_timezone' => 'UTC',
5859
'input' => 'string',
5960
'date_widget' => 'choice',
61+
'years' => array(2010),
6062
'time_widget' => 'choice',
6163
));
6264

@@ -82,6 +84,7 @@ public function testSubmitTimestamp()
8284
'view_timezone' => 'UTC',
8385
'input' => 'timestamp',
8486
'date_widget' => 'choice',
87+
'years' => array(2010),
8588
'time_widget' => 'choice',
8689
));
8790

@@ -108,12 +111,13 @@ public function testSubmitWithoutMinutes()
108111
'model_timezone' => 'UTC',
109112
'view_timezone' => 'UTC',
110113
'date_widget' => 'choice',
114+
'years' => array(2010),
111115
'time_widget' => 'choice',
112116
'input' => 'datetime',
113117
'with_minutes' => false,
114118
));
115119

116-
$form->setData(new \DateTime('2010-06-02 03:04:05 UTC'));
120+
$form->setData(new \DateTime());
117121

118122
$input = array(
119123
'date' => array(
@@ -137,12 +141,13 @@ public function testSubmitWithSeconds()
137141
'model_timezone' => 'UTC',
138142
'view_timezone' => 'UTC',
139143
'date_widget' => 'choice',
144+
'years' => array(2010),
140145
'time_widget' => 'choice',
141146
'input' => 'datetime',
142147
'with_seconds' => true,
143148
));
144149

145-
$form->setData(new \DateTime('2010-06-02 03:04:05 UTC'));
150+
$form->setData(new \DateTime());
146151

147152
$input = array(
148153
'date' => array(
@@ -168,6 +173,7 @@ public function testSubmitDifferentTimezones()
168173
'model_timezone' => 'America/New_York',
169174
'view_timezone' => 'Pacific/Tahiti',
170175
'date_widget' => 'choice',
176+
'years' => array(2010),
171177
'time_widget' => 'choice',
172178
'input' => 'string',
173179
'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
@@ -187,6 +187,7 @@ public function testSubmitFromChoice()
187187
'model_timezone' => 'UTC',
188188
'view_timezone' => 'UTC',
189189
'widget' => 'choice',
190+
'years' => array(2010),
190191
));
191192

192193
$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

@@ -564,7 +577,7 @@ private function parseBlockScalar($style, $chomping = '', $indentation = 0)
564577
$previousLineIndented = false;
565578
$previousLineBlank = false;
566579

567-
for ($i = 0; $i < count($blockLines); $i++) {
580+
for ($i = 0; $i < count($blockLines); ++$i) {
568581
if ('' === $blockLines[$i]) {
569582
$text .= "\n";
570583
$previousLineIndented = false;
@@ -659,7 +672,7 @@ private function isCurrentLineComment()
659672
//checking explicitly the first char of the trim is faster than loops or strpos
660673
$ltrimmedLine = ltrim($this->currentLine, ' ');
661674

662-
return $ltrimmedLine[0] === '#';
675+
return '' !== $ltrimmedLine && $ltrimmedLine[0] === '#';
663676
}
664677

665678
/**

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

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

817817
public function getCommentLikeStringInScalarBlockData()
818818
{
819-
$yaml1 = <<<'EOT'
819+
$tests = array();
820+
821+
$yaml = <<<'EOT'
820822
pages:
821823
-
822824
title: some title
@@ -831,7 +833,7 @@ public function getCommentLikeStringInScalarBlockData()
831833
832834
footer # comment3
833835
EOT;
834-
$expected1 = array(
836+
$expected = array(
835837
'pages' => array(
836838
array(
837839
'title' => 'some title',
@@ -850,8 +852,9 @@ public function getCommentLikeStringInScalarBlockData()
850852
),
851853
),
852854
);
855+
$tests[] = array($yaml, $expected);
853856

854-
$yaml2 = <<<'EOT'
857+
$yaml = <<<'EOT'
855858
test: |
856859
foo
857860
# bar
@@ -866,7 +869,7 @@ public function getCommentLikeStringInScalarBlockData()
866869
# bar
867870
baz
868871
EOT;
869-
$expected2 = array(
872+
$expected = array(
870873
'test' => <<<'EOT'
871874
foo
872875
# bar
@@ -893,11 +896,47 @@ public function getCommentLikeStringInScalarBlockData()
893896
),
894897
),
895898
);
899+
$tests[] = array($yaml, $expected);
896900

897-
return array(
898-
array($yaml1, $expected1),
899-
array($yaml2, $expected2),
901+
$yaml = <<<EOT
902+
foo:
903+
bar:
904+
scalar-block: >
905+
line1
906+
line2>
907+
baz:
908+
# comment
909+
foobar: ~
910+
EOT;
911+
$expected = array(
912+
'foo' => array(
913+
'bar' => array(
914+
'scalar-block' => 'line1 line2>',
915+
),
916+
'baz' => array(
917+
'foobar' => null,
918+
),
919+
),
900920
);
921+
$tests[] = array($yaml, $expected);
922+
923+
$yaml = <<<'EOT'
924+
a:
925+
b: hello
926+
# c: |
927+
# first row
928+
# second row
929+
d: hello
930+
EOT;
931+
$expected = array(
932+
'a' => array(
933+
'b' => 'hello',
934+
'd' => 'hello',
935+
),
936+
);
937+
$tests[] = array($yaml, $expected);
938+
939+
return $tests;
901940
}
902941

903942
public function testBlankLinesAreParsedAsNewLinesInFoldedBlocks()

0 commit comments

Comments
 (0)
0