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

Fix bug in function name comparison. #609

Merged
merged 3 commits into from
Jul 17, 2016

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 16, 2016

AbstractFunctionRestrictionsSniff did not allow for case-insensitive comparison of function names.

Note: Function names are case-insensitive, though it is usually good form to call functions as they appear in their declaration.

Ref: http://php.net/manual/en/functions.user-defined.php

Also:

  • Better be safe than sorry, so preg_quote()-ing the function names passed to this class.
  • Minor memory management improvement: no need to remember the matched function name.

The first commit adds a unit test proving the bug. The second commit fixes the bug.

@jrfnl jrfnl force-pushed the WPCS/feature/case-insensitive-function-name-compare branch from 0b29cff to 4a527b9 Compare July 17, 2016 03:24
jrfnl added 2 commits July 17, 2016 05:24
AbstractFunctionRestrictionsSniff did not allow for case-insensitive comparison of function names.

> **Note**: Function names are case-insensitive, though it is usually good form to call functions as they appear in their declaration.

Ref: http://php.net/manual/en/functions.user-defined.php

Also:
* Better be safe than sorry, so `preg_quote()`-ing the function names passed to this class.
* Minor memory management improvement: no need to remember the matched function name.
@jrfnl
Copy link
Member Author

jrfnl commented Jul 17, 2016

Interesting. I just found another bug in this class which I had apparently accidentally fixed as well.

The wildcard replacement was not just replacing the *, but also the character before it. While for now, wildcard function groups was only used for curl_*, I expect this will be used more soon.

Example of the effect of the bug:
curlyhair(); should not match, but did.

Added unit test to that effect.

@JDGrimes JDGrimes added this to the 0.10.0 milestone Jul 17, 2016
@JDGrimes JDGrimes merged commit a17b52d into develop Jul 17, 2016
@JDGrimes JDGrimes deleted the WPCS/feature/case-insensitive-function-name-compare branch July 17, 2016 18:06
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.

3 participants