-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Yaml][Inline] Fail properly on empty object tag and empty const tag #35332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -506,7 +506,12 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = [] | |
|
||
if ('!php/const' === $key) { | ||
$key .= self::parseScalar($mapping, $flags, [':', ' '], $i, false, [], true); | ||
$key = self::evaluateScalar($key, $flags); | ||
if ('!php/const:' === $key && ':' !== $mapping[$i]) { | ||
$key = ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to evaluate because we know it's gonna end up as the empty string (the key === |
||
--$i; | ||
} else { | ||
$key = self::evaluateScalar($key, $flags); | ||
} | ||
} | ||
|
||
if (':' !== $key && false === $i = strpos($mapping, ':', $i)) { | ||
|
@@ -692,6 +697,10 @@ private static function evaluateScalar($scalar, $flags, $references = []) | |
return null; | ||
case 0 === strpos($scalar, '!php/object'): | ||
if (self::$objectSupport) { | ||
if (!isset($scalar[12])) { | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
return unserialize(self::parseScalar(substr($scalar, 12))); | ||
} | ||
|
||
|
@@ -717,6 +726,10 @@ private static function evaluateScalar($scalar, $flags, $references = []) | |
return null; | ||
case 0 === strpos($scalar, '!php/const'): | ||
if (self::$constantSupport) { | ||
if (!isset($scalar[11])) { | ||
return ''; | ||
} | ||
|
||
$i = 0; | ||
if (\defined($const = self::parseScalar(substr($scalar, 11), 0, null, $i, false))) { | ||
return \constant($const); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -799,4 +799,47 @@ public function getTestsForOctalNumbers() | |
'negative octal number' => [-28, '-034'], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider phpObjectTagWithEmptyValueProvider | ||
*/ | ||
public function testPhpObjectWithEmptyValue($expected, $value) | ||
{ | ||
$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_OBJECT)); | ||
} | ||
|
||
public function phpObjectTagWithEmptyValueProvider() | ||
{ | ||
return [ | ||
[false, '!php/object'], | ||
[false, '!php/object '], | ||
[false, '!php/object '], | ||
[[false], '[!php/object]'], | ||
[[false], '[!php/object ]'], | ||
[[false, 'foo'], '[!php/object , foo]'], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider phpConstTagWithEmptyValueProvider | ||
*/ | ||
public function testPhpConstTagWithEmptyValue($expected, $value) | ||
{ | ||
$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_CONSTANT)); | ||
} | ||
|
||
public function phpConstTagWithEmptyValueProvider() | ||
{ | ||
return [ | ||
['', '!php/const'], | ||
['', '!php/const '], | ||
['', '!php/const 10000 '], | ||
This comment was marked as outdated.
Sorry, something went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i mean, if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. never mind :D it's still OK if it would be defined. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would work but only with no error reporting on notices. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anyway that's such a weird case. I think it doesn't matter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No. My previous replies were to your first message. If the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes we can stay backward compatible by checking it. But do we want to? 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, but that's for 5.x. It would make the feature removal/deprecation more explicit. |
||
[[''], '[!php/const]'], | ||
[[''], '[!php/const ]'], | ||
[['', 'foo'], '[!php/const , foo]'], | ||
[['' => 'foo'], '{!php/const: foo}'], | ||
[['' => 'foo'], '{!php/const : foo}'], | ||
[['' => 'foo', 'bar' => 'ccc'], '{!php/const : foo, bar: ccc}'], | ||
]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bug fix.
{!php/const: foo}
is currently interpreted as legacyphp/const:
tag +''
as the const value while it should end up as['' => 'foo']
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this must be removed once merged to 4.3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref #35318 btw