|
19 | 19 | */
|
20 | 20 | class Parser
|
21 | 21 | {
|
| 22 | + const FOLDED_SCALAR_PATTERN = '(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?'; |
| 23 | + |
22 | 24 | private $offset = 0;
|
23 | 25 | private $lines = array();
|
24 | 26 | private $currentLineNb = -1;
|
@@ -304,10 +306,15 @@ private function getNextEmbedBlock($indentation = null)
|
304 | 306 |
|
305 | 307 | $isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine);
|
306 | 308 |
|
307 |
| - // We are in string block (ie. after a line ending with "|") |
308 |
| - $removeComments = !preg_match('~(.*)\|[\s]*$~', $this->currentLine); |
| 309 | + // Comments must not be removed inside a string block (ie. after a line ending with "|") |
| 310 | + $removeCommentsPattern = '~'.self::FOLDED_SCALAR_PATTERN.'$~'; |
| 311 | + $removeComments = !preg_match($removeCommentsPattern, $this->currentLine); |
309 | 312 |
|
310 | 313 | while ($this->moveToNextLine()) {
|
| 314 | + if ($this->getCurrentLineIndentation() === $newIndent) { |
| 315 | + $removeComments = !preg_match($removeCommentsPattern, $this->currentLine); |
| 316 | + } |
| 317 | + |
311 | 318 | if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine)) {
|
312 | 319 | $this->moveToPreviousLine();
|
313 | 320 | break;
|
@@ -389,7 +396,7 @@ private function parseValue($value, $exceptionOnInvalidType, $objectSupport)
|
389 | 396 | return $this->refs[$value];
|
390 | 397 | }
|
391 | 398 |
|
392 |
| - if (preg_match('/^(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?$/', $value, $matches)) { |
| 399 | + if (preg_match('/^'.self::FOLDED_SCALAR_PATTERN.'$/', $value, $matches)) { |
393 | 400 | $modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';
|
394 | 401 |
|
395 | 402 | return $this->parseFoldedScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), intval(abs($modifiers)));
|
|
0 commit comments