Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit da327c7

Browse filesBrowse files
committed
parse unquoted digits in tag values as integers
1 parent 1313c45 commit da327c7
Copy full SHA for da327c7

File tree

5 files changed

+26
-19
lines changed
Filter options

5 files changed

+26
-19
lines changed

‎src/Symfony/Component/Yaml/Inline.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static function parse(string $value = null, int $flags = 0, array &$refer
8686
++$i;
8787
break;
8888
default:
89-
$result = self::parseScalar($value, $flags, null, $i, null === $tag, $references);
89+
$result = self::parseScalar($value, $flags, null, $i, true, $references);
9090
}
9191

9292
// some comments are allowed at the end
@@ -657,7 +657,6 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
657657
}
658658

659659
return octdec($value);
660-
// Optimize for returning strings.
661660
case \in_array($scalar[0], ['+', '-', '.'], true) || is_numeric($scalar[0]):
662661
if (Parser::preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar)) {
663662
$scalar = str_replace('_', '', $scalar);

‎src/Symfony/Component/Yaml/Tests/DumperTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/DumperTest.php
+1-8Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,6 @@ public function testDumpingTaggedValueSequenceWithInlinedTagValues()
492492
493493
YAML;
494494
$this->assertSame($expected, $yaml);
495-
// @todo Fix the parser, preserve numbers.
496-
$data[2] = new TaggedValue('number', '5');
497495
$this->assertSameData($data, $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS));
498496
}
499497

@@ -522,8 +520,6 @@ public function testDumpingTaggedValueMapRespectsInlineLevel()
522520
523521
YAML;
524522
$this->assertSame($expected, $yaml);
525-
// @todo Fix the parser, preserve numbers.
526-
$data['count'] = new TaggedValue('number', '5');
527523
$this->assertSameData($data, $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS));
528524
}
529525

@@ -577,9 +573,6 @@ public function testDumpingNotInlinedNullTaggedValue()
577573
YAML;
578574

579575
$this->assertSame($expected, $this->dumper->dump($data, 2));
580-
581-
// @todo Fix the parser, don't stringify null.
582-
$data['foo'] = new TaggedValue('bar', 'null');
583576
$this->assertSameData($data, $this->parser->parse($expected, Yaml::PARSE_CUSTOM_TAGS | Yaml::PARSE_CONSTANT));
584577
}
585578

@@ -696,7 +689,7 @@ public function testDumpMultiLineStringAsScalarBlock()
696689
nested_inlined_multi_line_string: { inlined_multi_line: "foo\nbar\r\nempty line:\n\nbaz" }
697690

698691
YAML
699-
);
692+
);
700693
$this->assertSame($expected, $yml);
701694
$this->assertSame($data, $this->parser->parse($yml));
702695
}

‎src/Symfony/Component/Yaml/Tests/Fixtures/YtsSpecificationExamples.yml

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/Fixtures/YtsSpecificationExamples.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ yaml: |
913913
no int: ! 12
914914
string: !!str 12
915915
php: |
916-
[ 'integer' => 12, 'no int' => '12', 'string' => '12' ]
916+
[ 'integer' => 12, 'no int' => 12, 'string' => '12' ]
917917
---
918918
test: Private types
919919
todo: true

‎src/Symfony/Component/Yaml/Tests/InlineTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/InlineTest.php
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,24 @@ public function testTagWithEmptyValueInMapping()
743743
$this->assertSame('', $value['foo']->getValue());
744744
}
745745

746+
public function testTagWithQuotedInteger()
747+
{
748+
$value = Inline::parse('!number "5"', Yaml::PARSE_CUSTOM_TAGS);
749+
750+
$this->assertInstanceOf(TaggedValue::class, $value);
751+
$this->assertSame('number', $value->getTag());
752+
$this->assertSame('5', $value->getValue());
753+
}
754+
755+
public function testTagWithUnquotedInteger()
756+
{
757+
$value = Inline::parse('!number 5', Yaml::PARSE_CUSTOM_TAGS);
758+
759+
$this->assertInstanceOf(TaggedValue::class, $value);
760+
$this->assertSame('number', $value->getTag());
761+
$this->assertSame(5, $value->getValue());
762+
}
763+
746764
public function testUnfinishedInlineMap()
747765
{
748766
$this->expectException(ParseException::class);
@@ -769,6 +787,7 @@ public function getTestsForOctalNumbers()
769787

770788
/**
771789
* @group legacy
790+
*
772791
* @dataProvider getTestsForOctalNumbersYaml11Notation
773792
*/
774793
public function testParseOctalNumbersYaml11Notation(int $expected, string $yaml, string $replacement)

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/ParserTest.php
+4-8Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,16 @@ public function testTaggedValueTopLevelNumber()
5454
{
5555
$yml = '!number 5';
5656
$data = $this->parser->parse($yml, Yaml::PARSE_CUSTOM_TAGS);
57-
// @todo Preserve the number, don't turn into string.
58-
$expected = new TaggedValue('number', '5');
57+
$expected = new TaggedValue('number', 5);
5958
$this->assertSameData($expected, $data);
6059
}
6160

6261
public function testTaggedValueTopLevelNull()
6362
{
6463
$yml = '!tag null';
6564
$data = $this->parser->parse($yml, Yaml::PARSE_CUSTOM_TAGS);
66-
// @todo Preserve literal null, don't turn into string.
67-
$expected = new TaggedValue('tag', 'null');
68-
$this->assertSameData($expected, $data);
65+
66+
$this->assertSameData(new TaggedValue('tag', null), $data);
6967
}
7068

7169
public function testTaggedValueTopLevelString()
@@ -1555,8 +1553,6 @@ public function testParseDateAsMappingValue()
15551553
}
15561554

15571555
/**
1558-
* @param $lineNumber
1559-
* @param $yaml
15601556
* @dataProvider parserThrowsExceptionWithCorrectLineNumberProvider
15611557
*/
15621558
public function testParserThrowsExceptionWithCorrectLineNumber($lineNumber, $yaml)
@@ -2310,7 +2306,7 @@ public function taggedValuesProvider()
23102306

23112307
public function testNonSpecificTagSupport()
23122308
{
2313-
$this->assertSame('12', $this->parser->parse('! 12'));
2309+
$this->assertSame(12, $this->parser->parse('! 12'));
23142310
}
23152311

23162312
public function testCustomTagsDisabled()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.