8000 fixed parser · symfony/symfony@31b0472 · GitHub
[go: up one dir, main page]

Skip to content

Commit 31b0472

Browse files
a1812nicolas-grekas
authored andcommitted
fixed parser
1 parent f651ce6 commit 31b0472

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,16 @@ private function doParse(string $value, int $flags)
169169
}
170170

171171
// array
172-
if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) {
172+
if (isset($values['value']) && 0 === strpos(ltrim($values['value'], ' '), '-')) {
173+
// Inline first child
174+
$currentLineNumber = $this->getRealCurrentLineNb();
175+
176+
$sequenceIndentation = \strlen($values['leadspaces']) + 1;
177+
$sequenceYaml = substr($this->currentLine, $sequenceIndentation);
178+
$sequenceYaml .= "\n".$this->getNextEmbedBlock($sequenceIndentation, true);
179+
180+
$data[] = $this->parseBlock($currentLineNumber, rtrim($sequenceYaml), $flags);
181+
} elseif (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) {
173182
$data[] = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true) ?? '', $flags);
174183
} elseif (null !== $subTag = $this->getLineTag(ltrim($values['value'], ' '), $flags)) {
175184
$data[] = new TaggedValue(
@@ -604,6 +613,7 @@ private function getNextEmbedBlock(int $indentation = null, bool $inSequence = f
604613
}
605614

606615
$data< 10000 /span> = [];
616+
607617
if ($this->getCurrentLineIndentation() >= $newIndent) {
608618
$data[] = substr($this->currentLine, $newIndent);
609619
} elseif ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()) {

src/Symfony/Component/Yaml/Tests/Fixtures/YtsBasicTests.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,37 @@ php: |
200200
'age' => 38
201201
]
202202
]
203+
---
204+
test: Inline first element in sequence blocks 1
205+
yaml: |
206+
- - s1_i1
207+
- s1_i2
208+
- s2
209+
php: |
210+
[
211+
[
212+
"s1_i1",
213+
"s1_i2"
214+
],
215+
"s2"
216+
]
217+
---
218+
test: Inline first element in sequence blocks 2
219+
yaml: |
220+
- - s1_i1
221+
- - s1_i1_1
222+
- s1_i1_2
223+
- s1_i2
224+
- s2
225+
php: |
226+
[
227+
[
228+
"s1_i1",
229+
[
230+
"s1_i1_1",
231+
"s1_i1_2",
232+
],
233+
"s1_i2"
234+
],
235+
"s2"
236+
]

0 commit comments

Comments
 (0)
0