Skip to content

Commit c66ed68

Browse files
committed
bug symfony#24410 [Yaml] fix refreshing line numbers for the inline parser (xabbuh)
This PR was merged into the 3.4 branch. Discussion ---------- [Yaml] fix refreshing line numbers for the inline parser | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- 5518896 fix refreshing line numbers for the inline parser
2 parents dcca180 + 5518896 commit c66ed68

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@ class Inline
3939
* @param int|null $parsedLineNumber
4040
* @param string|null $parsedFilename
4141
*/
42-
public static function initialize($flags, $parsedLineNumber = 0, $parsedFilename = null)
42+
public static function initialize($flags, $parsedLineNumber = null, $parsedFilename = null)
4343
{
4444
self::$exceptionOnInvalidType = (bool) (Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE & $flags);
4545
self::$objectSupport = (bool) (Yaml::PARSE_OBJECT & $flags);
4646
self::$objectForMap = (bool) (Yaml::PARSE_OBJECT_FOR_MAP & $flags);
4747
self::$constantSupport = (bool) (Yaml::PARSE_CONSTANT & $flags);
4848
self::$parsedFilename = $parsedFilename;
49-
self::$parsedLineNumber = $parsedLineNumber;
49+
50+
if (null !== $parsedLineNumber) {
51+
self::$parsedLineNumber = $parsedLineNumber;
52+
}
5053
}
5154

5255
/**

src/Symfony/Component/Yaml/Parser.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ private function doParse($value, $flags)
201201
throw new ParseException('A YAML file cannot contain tabs as indentation.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
202202
}
203203

204+
Inline::initialize($flags, $this->getRealCurrentLineNb(), $this->filename);
205+
204206
$isRef = $mergeNode = false;
205207
if (self::preg_match('#^\-((?P<leadspaces>\s+)(?P<value>.+))?$#u', rtrim($this->currentLine), $values)) {
206208
if ($context && 'mapping' == $context) {
@@ -252,7 +254,6 @@ private function doParse($value, $flags)
252254
}
253255
$context = 'mapping';
254256

255-
Inline::initialize($flags, $this->getRealCurrentLineNb(), $this->filename);
256257
try {
257258
$i = 0;
258259
$evaluateKey = !(Yaml::PARSE_KEYS_AS_STRINGS & $flags);
@@ -402,7 +403,6 @@ private function doParse($value, $flags)
402403
// 1-liner optionally followed by newline(s)
403404
if (is_string($value) && $this->lines[0] === trim($value)) {
404405
try {
405-
Inline::$parsedLineNumber = $this->getRealCurrentLineNb();
406406
$value = Inline::parse($this->lines[0], $flags, $this->refs);
407407
} catch (ParseException $e) {
408408
$e->setParsedLine($this->getRealCurrentLineNb() + 1);
@@ -744,7 +744,6 @@ private function parseValue($value, $flags, $context)
744744
}
745745
}
746746

747-
Inline::$parsedLineNumber = $this->getRealCurrentLineNb();
748747
$parsedValue = Inline::parse($value, $flags, $this->refs);
749748

750749
if ('mapping' === $context && is_string($parsedValue) && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,8 +1853,8 @@ public function testPhpConstantTagMappingKey()
18531853
/**
18541854
* @group legacy
18551855
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 2.
1856-
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 1.
1857-
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 1.
1856+
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 4.
1857+
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 5.
18581858
*/
18591859
public function testDeprecatedPhpConstantTagMappingKey()
18601860
{

0 commit comments

Comments
 (0)