Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit9d03478

Browse files
committed
tag for dumped PHP objects must be a local one
1 parent6d8078f commit9d03478

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
caseis_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
case0 ===strpos($scalar,'!'):
436436
return (int)self::parseScalar(substr($scalar,2));
437+
case0 ===strpos($scalar,'!php/object:'):
438+
if (self::$objectSupport) {
439+
returnunserialize(substr($scalar,12));
440+
}
441+
442+
if (self::$exceptionOnInvalidType) {
443+
thrownewParseException('Object support when parsing a YAML file has been disabled.');
444+
}
445+
446+
return;
437447
case0 ===strpos($scalar,'!!php/object:'):
438448
if (self::$objectSupport) {
439449
returnunserialize(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' =>newA(),'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
publicfunctiontestObjectSupportDisabledButNoExceptions()

‎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' =>newB(),'bar' =>1),$this->parser->parse($input,false,true),'->parse() is able to parse objects');
429-
}
430429

431-
publicfunctiontestObjectSupportDisabledButNoExceptions()
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' =>newB(),'bar' =>1),$this->parser->parse($input,false,true),'->parse() is able to parse objects');
435+
}
437436

437+
/**
438+
* @dataProvider invalidDumpedObjectProvider
439+
*/
440+
publicfunctiontestObjectSupportDisabledButNoExceptions($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-
publicfunctiontestObjectsSupportDisabledWithExceptions()
449+
publicfunctiontestObjectsSupportDisabledWithExceptions($yaml)
450+
{
451+
$this->parser->parse($yaml,true,false);
452+
}
453+
454+
publicfunctioninvalidDumpedObjectProvider()
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+
returnarray(
466+
'yaml-tag' =>array($yamlTag),
467+
'local-tag' =>array($localTag),
468+
);
447469
}
448470

449471
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp