Skip to content

[2.3] Static Code Analysis for Components #14800

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 7 commits into from
Closed

[2.3] Static Code Analysis for Components #14800

wants to merge 7 commits into from

Conversation

kalessil
Copy link
Contributor

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

Static Code Analysis with Php Inspections (EA Extended):
- not optimal regular expressions usage
- strlen miss-use
- not optimal conditional statements in Process and Filesystem
- unsafe uniquid usage
- missing throws annotations

    - not optimal regular expressions usage
    - strlen miss-use
    - not optimal conditionals in Process and Filesystem
    - unsafe uniquid usage
@@ -209,8 +209,8 @@ public function getDefaultValue()
*/
public function addChild(NodeInterface $node)
{
$name = $node->getName();
if (!strlen($name)) {
$name = (string) $node->getName();
Copy link
Member

Choose a reason for hiding this comment

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

The cast is not necessary. getName() returns a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried to add validation into base node if string provided as name, UTs crashed.

Original code allows 0 and false, so I just put this visible - inspire of PhpDoc it's possible to provide non-string values as name, so perhaps it's a new bug discovered.

Copy link
Member

Choose a reason for hiding this comment

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

Where do you see that one can provide non-string values as names?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

\Symfony\Component\Config\Definition\BaseNode::__construct doesn't validate a type.

And validation will break some of UTs, I didn't look into details as very constraint in time.

upd: 2 other setters don't check type as well
\Symfony\Component\Config\Definition\ArrayNode::setName
\Symfony\Component\Config\Definition\VariableNode::setName

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xabbuh : I can just revert this change and create a bug-report, what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Well, we don't do any checking for scalar types in Symfony. But the docblock clearly states that you have to pass string values. Thus, yes, please revert that change. But I don't think it is necessary to open an issue for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, shall I also revert then changes in Symfony/Component/Security/Acl/Domain/DoctrineAclCache.php, as I added a scalar type check?

Copy link
Member

Choose a reason for hiding this comment

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

please do that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xabbuh : done, in nutshell strlen's are forcing string context, covering issues with types, very elegant but not obvious hack.

@@ -589,7 +589,7 @@ protected function getAbsoluteUri($uri)
$uri = $path.$uri;
}

return preg_replace('#^(.*?//[^/]+)\/.*$#', '$1', $currentUri).$uri;
return preg_replace('#^([^/]*//[^/]+)\/.*$#', '$1', $currentUri).$uri;
Copy link
Member

Choose a reason for hiding this comment

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

Those are not equivalent. You cannot replace .*? or .+? like you are doing. All those changes should be reverted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will revert.

@@ -202,7 +202,7 @@ public static function phpize($value)
return '0x' === $value[0].$value[1] ? hexdec($value) : (float) $value;
case preg_match('/^0x[0-9a-f]++$/i', $value):
return hexdec($value);
case preg_match('/^(-|\+)?[0-9]+(\.[0-9]+)?$/', $value):
case preg_match('/^(-|\+)?\d+(\.\d+)?$/', $value):
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the point/advantage of changing that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[0-9] not supporting Unicode digits

// matches Unicode digits, e.g. Arabic
preg_match('/\d+/u', '٠١٢٣٤٥٦٧٨٩', $m);
var_dump($m);

// will not match Unicode digits
preg_match('/\[0-9]+/u', '٠١٢٣٤٥٦٧٨٩', $m);
var_dump($m);

Copy link
Member

Choose a reason for hiding this comment

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

whihc means your change is changing the feature, and so should be submitted separately as a feature addition (and not on 2.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.

Not really,

I didn't introduce /u modifier, so [0-9] -> \d not changing behavior,
but can be safely switched to use unicode later (if the feature requested just /u modifier needs to be added).

Copy link
Contributor

Choose a reason for hiding this comment

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

'/\d+/u' makes it support unicode numerics? Cool :)

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, the same for \w, \W.

@kalessil
Copy link
Contributor Author

kalessil commented Jun 2, 2015

Reverted \d, \w to not confuse people.

@kalessil kalessil closed this Jun 4, 2015
fabpot added a commit that referenced this pull request Sep 14, 2015
This PR was squashed before being merged into the 2.3 branch (closes #14802).

Discussion
----------

[HttpKernel] fix broken multiline <esi:remove>

|Q            |A  |
|---          |---|
|Bug Fix?     |yes|
|New Feature? |n  |
|BC Breaks?   |n  |
|Deprecations?|n  |
|Tests Pass?  |yes|
|Fixed Tickets|   |
|License      |MIT|
|Doc PR       |   |

Originally found in #14800 (diff)

`<esi:remove>` blocks with multiline contents were not removed.
`<esi:comment>` blocks with multiline contents were not removed.

Note. According to http://www.w3.org/TR/esi-lang
`comment is an empty element, and must not have an end tag.` so the support for multi line comments are not actually supported in the standard.

Commits
-------

06f97bf [HttpKernel] fix broken multiline <esi:remove>
fabpot added a commit to symfony/http-kernel that referenced this pull request Sep 14, 2015
This PR was squashed before being merged into the 2.3 branch (closes #14802).

Discussion
----------

[HttpKernel] fix broken multiline <esi:remove>

|Q            |A  |
|---          |---|
|Bug Fix?     |yes|
|New Feature? |n  |
|BC Breaks?   |n  |
|Deprecations?|n  |
|Tests Pass?  |yes|
|Fixed Tickets|   |
|License      |MIT|
|Doc PR       |   |

Originally found in symfony/symfony#14800 (diff)

`<esi:remove>` blocks with multiline contents were not removed.
`<esi:comment>` blocks with multiline contents were not removed.

Note. According to http://www.w3.org/TR/esi-lang
`comment is an empty element, and must not have an end tag.` so the support for multi line comments are not actually supported in the standard.

Commits
-------

06f97bf [HttpKernel] fix broken multiline <esi:remove>
@kalessil kalessil deleted the 2.3-SCA2 branch December 21, 2015 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants