Skip to content

[DependencyInjection] Yaml: check if $tags is an array before using it #21348

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

Closed
wants to merge 3 commits into from

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Jan 19, 2017

Q A
Branch? master
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

@dunglas dunglas changed the title [DependencyInjection] Yaml: check if is an array before using it [DependencyInjection] Yaml: check if $tags is an array before using it Jan 19, 2017
@@ -331,7 +331,15 @@ private function parseDefinition($id, $service, $file, array $defaults)
}
}

$tags = isset($service['tags']) ? $service['tags'] : array();
Copy link
Member

Choose a reason for hiding this comment

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

I think this line was fine, just add if (!is_array($tags)) { on the next line

Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this PR be applied on a lower branch btw?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why not but it adds 1 useless check when $service['tags'] is not set.

Copy link
Member Author

@dunglas dunglas Jan 19, 2017

Choose a reason for hiding this comment

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

No the branch is correct (this "bug" was introduced by _defaults in #21071).

Copy link
Member

@nicolas-grekas nicolas-grekas Jan 19, 2017

Choose a reason for hiding this comment

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

it adds 1 useless check

yes, but we don't care, readibility is more important here (thinking about the complexity of nested if/else blocks) IMHO

Copy link
Member Author

Choose a reason for hiding this comment

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

I usually prefer if/else than the ternary operator but it's probably because I need glasses to read on a screen.
I'll change that.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@xabbuh
Copy link
Member

xabbuh commented Jan 19, 2017

We should add a test then to avoid future regressions.

@dunglas
Copy link
Member Author

dunglas commented Jan 20, 2017

@xabbuh test added

@nicolas-grekas
Copy link
Member

Tests fail :)

@dunglas
Copy link
Member Author

dunglas commented Jan 20, 2017

Fixed.

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

👍

Status: Reviewed


Foo\Bar:
tags: invalid
inherit_tags: true
Copy link
Member

Choose a reason for hiding this comment

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

I find this test confusing. Intuitively, I thought that tags were inherited and then validated, so the Foo\Bar service has the valid tags: ['foo'] tags instead of tags: invalid

Copy link
Member

Choose a reason for hiding this comment

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

But this way (using a string instead of an array) to specify tags already wasn't supported before. Why should we do that now?

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Jan 24, 2017
@nicolas-grekas
Copy link
Member

Thank you @dunglas.

nicolas-grekas added a commit that referenced this pull request Jan 24, 2017
…efore using it (dunglas)

This PR was squashed before being merged into the 3.3-dev branch (closes #21348).

Discussion
----------

[DependencyInjection] Yaml: check if $tags is an array before using it

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Commits
-------

1c9b5c9 [DependencyInjection] Yaml: check if  is an array before using it
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.

5 participants