8000 bug #17461 [Yaml] tag for dumped PHP objects must be a local one (xab… · symfony/symfony@385f23e · GitHub
[go: up one dir, main page]

Skip to content

Commit 385f23e

Browse files
committed
bug #17461 [Yaml] tag for dumped PHP objects must be a local one (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [Yaml] tag for dumped PHP objects must be a local one | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #16877 | License | MIT | Doc PR | Commits ------- 9d03478 tag for dumped PHP objects must be a local one
2 parents 6eda9ad + 9d03478 commit 385f23e

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp
102102
return 'null';
103103
case is_object($value):
104104
if ($objectSupport) {
105-
return '!!php/object:'.serialize($value);
105+
return '!php/object:'.serialize($value);
106106
}
107107

108108
if ($exceptionOnInvalidType) {
@@ -434,6 +434,16 @@ private static function evaluateScalar($scalar, $references = array())
434434
return (string) substr($scalar, 5);
435435
case 0 === strpos($scalar, '! '):
436436
return (int) self::parseScalar(substr($scalar, 2));
437+
case 0 === strpos($scalar, '!php/object:'):
438+
if (self::$objectSupport) {
439+
return unserialize(substr($ 8000 scalar, 12));
440+
}
441+
442+
if (self::$exceptionOnInvalidType) {
443+
throw new ParseException('Object support when parsing a YAML file has been disabled.');
444+
}
445+
446+
return;
437447
case 0 === strpos($scalar, '!!php/object:'):
438448
if (self::$objectSupport) {
439449
return unserialize(substr($scalar, 13));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function testObjectSupportEnabled()
181181
{
182182
$dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, true);
183183

184-
$this->assertEquals('{ foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $dump, '->dump() is able to dump objects');
184+
$this->assertEquals('{ foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', $dump, '->dump() is able to dump objects');
185185
}
186186

187187
public function testObjectSupportDisabledButNoExceptions()

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,24 +426,46 @@ public function testObjectSupportEnabled()
426426
bar: 1
427427
EOF;
428428
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
429-
}
430429

431-
public function testObjectSupportDisabledButNoExceptions()
432-
{
433430
$input = <<<EOF
434-
foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
431+
foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
435432
bar: 1
436433
EOF;
434+
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
435+
}
437436

437+
/**
438+
* @dataProvider invalidDumpedObjectProvider
439+
*/
440+
public function testObjectSupportDisabledButNoExceptions($input)
441+
{
438442
$this->assertEquals(array('foo' => null, 'bar' => 1), $this->parser->parse($input), '->parse() does not parse objects');
439443
}
440444

441445
/**
446+
* @dataProvider invalidDumpedObjectProvider
442447
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
443448
*/
444-
public function testObjectsSupportDisabledWithExceptions()
449+
public function testObjectsSupportDisabledWithExceptions($yaml)
450+
{
451+
$this->parser->parse($yaml, true, false);
452+
}
453+
454+
public function invalidDumpedObjectProvider()
445455
{
446-
$this->parser->parse('foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}', true, false);
456+
$yamlTag = <<<EOF
457+
foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
458+
bar: 1
459+
EOF;
460+
$localTag = <<<EOF
461+
foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
462+
bar: 1
463+
EOF;
464+
465+
return array(
466+
'yaml-tag' => array($yamlTag),
467+
'local-tag' => array($localTag),
468+
);
447469
}
448470

449471
/**

0 commit comments

Comments
 (0)
0