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

Commitf146c8d

Browse files
committed
tag for dumped PHP objects must be a local one
1 parenta729462 commitf146c8d

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
@@ -105,7 +105,7 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp
105105
return'null';
106106
caseis_object($value):
107107
if ($objectSupport) {
108-
return'!!php/object:'.serialize($value);
108+
return'!php/object:'.serialize($value);
109109
}
110110

111111
if ($exceptionOnInvalidType) {
@@ -476,6 +476,16 @@ private static function evaluateScalar($scalar, $references = array())
476476
return (string)substr($scalar,5);
477477
case0 ===strpos($scalar,'!'):
478478
return (int)self::parseScalar(substr($scalar,2));
479+
case0 ===strpos($scalar,'!php/object:'):
480+
if (self::$objectSupport) {
481+
returnunserialize(substr($scalar,12));
482+
}
483+
484+
if (self::$exceptionOnInvalidType) {
485+
thrownewParseException('Object support when parsing a YAML file has been disabled.');
486+
}
487+
488+
return;
479489
case0 ===strpos($scalar,'!!php/object:'):
480490
if (self::$objectSupport) {
481491
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
@@ -180,7 +180,7 @@ public function testObjectSupportEnabled()
180180
{
181181
$dump =$this->dumper->dump(array('foo' =>newA(),'bar' =>1),0,0,false,true);
182182

183-
$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');
183+
$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');
184184
}
185185

186186
publicfunctiontestObjectSupportDisabledButNoExceptions()

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,19 @@ 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

@@ -470,11 +474,29 @@ public function testObjectForMapIsAppliedAfterParsing()
470474
}
471475

472476
/**
477+
* @dataProvider invalidDumpedObjectProvider
473478
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
474479
*/
475-
publicfunctiontestObjectsSupportDisabledWithExceptions()
480+
publicfunctiontestObjectsSupportDisabledWithExceptions($yaml)
481+
{
482+
$this->parser->parse($yaml,true,false);
483+
}
484+
485+
publicfunctioninvalidDumpedObjectProvider()
476486
{
477-
$this->parser->parse('foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}',true,false);
487+
$yamlTag =<<<EOF
488+
foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
489+
bar: 1
490+
EOF;
491+
$localTag =<<<EOF
492+
foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
493+
bar: 1
494+
EOF;
495+
496+
returnarray(
497+
'yaml-tag' =>array($yamlTag),
498+
'local-tag' =>array($localTag),
499+
);
478500
}
479501

480502
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp