Skip to content
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

[Yaml][Inline] Fail properly on empty object tag and empty const tag #35332

Merged
merged 1 commit into from Feb 3, 2020

Conversation

fancyweb
Copy link
Contributor

Q A
Branch? 3.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

Rework of #35208 to not end up in parseScalar with an empty string or a boolean (and thus, avoid unfriendly error such as Trying to access array offset on value of type bool).

Ping @xabbuh

@fancyweb
Copy link
Contributor Author

Should we add this to the legacy tags btw?

@fancyweb fancyweb force-pushed the yaml-fail-on-empty-php-const branch 2 times, most recently from 1e9c967 to 5396cbc Compare January 14, 2020 09:35
@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Jan 14, 2020
src/Symfony/Component/Yaml/Inline.php Outdated Show resolved Hide resolved
src/Symfony/Component/Yaml/Inline.php Outdated Show resolved Hide resolved
@@ -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]) {
Copy link
Contributor Author

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 legacy php/const: tag + '' as the const value while it should end up as ['' => 'foo'].

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ref #35318 btw

@@ -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 = '';
Copy link
Contributor Author

@fancyweb fancyweb Jan 16, 2020

Choose a reason for hiding this comment

The 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 === !php/const).

@@ -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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unserialize('') === false

return [
['', '!php/const'],
['', '!php/const '],
['', '!php/const '],

This comment was marked as outdated.

Copy link
Contributor

@ro0NL ro0NL Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i mean, if constant(' ') were to be defined, the value would be "some"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind :D it's still OK if it would be defined.

Copy link
Contributor Author

@fancyweb fancyweb Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would work but only with no error reporting on notices.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind :D it's still OK if it would be defined.

No. My previous replies were to your first message. If the '' constant is defined, it is never resolved now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return defined('') ? constant('') : '';? 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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? 😅

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@nicolas-grekas
Copy link
Member

Thank you @fancyweb.

nicolas-grekas added a commit that referenced this pull request Feb 3, 2020
… const tag (fancyweb)

This PR was merged into the 3.4 branch.

Discussion
----------

[Yaml][Inline] Fail properly on empty object tag and empty const tag

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Rework of #35208 to not end up in `parseScalar` with an empty string or a boolean (and thus, avoid unfriendly error such as `Trying to access array offset on value of type bool`).

Ping @xabbuh

Commits
-------

bdf02c0 [Yaml][Inline] Fail properly on empty object tag and empty const tag
@nicolas-grekas nicolas-grekas merged commit bdf02c0 into symfony:3.4 Feb 3, 2020
fabpot added a commit that referenced this pull request Feb 3, 2020
…t a value (fancyweb)

This PR was merged into the 5.1-dev branch.

Discussion
----------

[Yaml] Deprecate using the object and const tag without a value

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| Deprecations? | yes
| Tickets       | #35332 (comment)
| License       | MIT
| Doc PR        | -

WIP because it needs 3.4 merged up into master + #35332.

Commits
-------

89062b9 [Yaml] Deprecate using the object and const tag without a value
This was referenced Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants