Skip to content

[FrameworkBundle] do not stumble upon empty tags #16932

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 1 commit into from

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Dec 9, 2015

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #16908
License MIT
Doc PR

@@ -49,4 +50,15 @@ public function testProcess()

$pass->process($container);
}

public function testEmptyTagNameIsIgnored()
Copy link
Contributor

Choose a reason for hiding this comment

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

this test is missing as assertion which is not good practice

@Tobion
Copy link
Contributor

Tobion commented Dec 10, 2015

I don't agree with this implementation. Either we say, empty tags are ignored. Then it should be ignored in findTags in the first place. Or we say empty tags are possible, but we only ignore them in UnusedTagsPass with the whitelist.

@Haehnchen
Copy link
Contributor

i simply extracted the empty tag by debugging inside findTags. generating an array with only empty strings there is looking wrong to me; just ignore them

@xabbuh xabbuh force-pushed the issue-16908 branch 2 times, most recently from be7f453 to c6a7c45 Compare December 10, 2015 20:39
@xabbuh
Copy link
Member Author

xabbuh commented Dec 10, 2015

I had a look at this again and I think the actual issue is that the XmlFileLoader does not enforce the tags to have a name (the YamlFileLoader actually has a test to enforce this behaviour, see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php#L224-L234). So I opened #16956 to enforce the same behaviour in the XmlFileLoader too and changed this one to simply ignore tags without a name (in case someone wrongly created tags this way manually).

@@ -59,7 +59,7 @@ public function process(ContainerBuilder $container)

foreach ($container->findUnusedTags() as $tag) {
// skip whitelisted tags
if (in_array($tag, $this->whitelist)) {
if (empty($tag) || in_array($tag, $this->whitelist)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this misses '0' as well. IMO an empty tag should still be reported as "unused". only the $candidates calculation should be skipped for empty tags.

@xabbuh
Copy link
Member Author

xabbuh commented Dec 19, 2015

I changed the implementation to skip only the check for similar tags when the current tag name is null or the empty string.


if (false !== strpos($definedTag, $tag) || levenshtein($tag, $definedTag) <= strlen($tag) / 3) {
$candidates[] = $definedTag;
if (null !== $tag && '' !== $tag) {
Copy link
Contributor

Choose a reason for hiding this comment

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

findUnusedTags has @return string[]. So $tag can never be null.

@Tobion
Copy link
Contributor

Tobion commented Dec 21, 2015

If #16956 is merged I don't think this change here has an relevance in reality as the tag name cannot be empty anymore.

@fabpot
Copy link
Member

fabpot commented Jan 25, 2016

Can we close this one then?

@xabbuh
Copy link
Member Author

xabbuh commented Jan 25, 2016

I think so. I'll finish #16956 tonight and then we don't need this anymore.

@xabbuh xabbuh closed this Jan 25, 2016
@xabbuh xabbuh deleted the issue-16908 branch January 25, 2016 13:16
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