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

Ruleset Tests: revert 485 and fix it #509

Merged
merged 1 commit into from
Jul 22, 2020

Conversation

jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented Jul 22, 2020

In #485, three tests were commented out because they seemed to break the ruleset tests.

At the request of Gary, I've had a look see to try and find the underlying cause.

Turned out to be a combination of three things:

  1. A new warning having been introduced in PHP 7.4 about using array access on non-arrays.
  2. The code in the test case file being incomplete/incorrect - required parameters for function calls were missing.
  3. The WPCS EscapeOutput not having enough defensive coding for when a faulty function call without parameters would be encountered.

Obviously we can't do anything about 1.

As for 3, I've opened a PR in WPCS upstream to fix this, but that fix won't be available to VIP until WPCS 3.0.0 has been released and VIPCS upgrades.
See: WordPress/WordPress-Coding-Standards#1939

So, in the mean time, let's make sure the function calls in the test case file which aren't intended to trigger the EscapeOutput sniff, don't trigger it.
And that's what's done in this PR.


To reproduce my findings / How to investigate this in the future:

  • Make sure you are set up to use PHP 7.4.x (or whatever other PHP version where the issue was first seen).
  • Run phpcs -ps --severity=1 --standard=WordPressVIPMinimum ./WordPressVIPMinimum/ruleset-test.inc
  • Take note of the missing errors/warnings.
  • Scroll to the top of the full report and see the cause, in this case:
  1 | ERROR   | An error occurred during processing; checking has been aborted. The error message was: Trying to access array offset on value of type bool
    |         | in path/to/WordPress/Sniffs/Security/EscapeOutputSniff.php on line 198 (Internal.Exception)

In 485, three tests were commented out because they seemed to break the ruleset tests.

At the request of Gary, I've had a look see to try and find the underlying cause.

Turned out to be a combination of three things:
1. A new warning having been introduced in PHP 7.4 about using array access on non-arrays.
2. The code in the test case file being incomplete/incorrect - required parameters for function calls were missing.
3. The WPCS `EscapeOutput` not having enough defensive coding for when a faulty function call without parameters would be encountered.

Obviously we can't do anything about 1.

As for 3, I've opened a PR in WPCS upstream to fix this, but that fix won't be available to VIP until WPCS 3.0.0 has been released and VIPCS upgrades.
See: WordPress/WordPress-Coding-Standards 1939

So, in the mean time, let's make sure the function calls in the test case file which aren't intended to trigger the `EscapeOutput` sniff, don't trigger it.
And that's what's done in this PR.

---

To reproduce my findings / How to investigate this in the future:
* Make sure you are set up to use PHP 7.4.x (or whatever other PHP version where the issue was first seen).
* Run `phpcs -ps --severity=1 --standard=WordPressVIPMinimum ./WordPressVIPMinimum/ruleset-test.inc`
* Take note of the missing errors/warnings.
* Scroll to the top of the full report and see the cause:
```
  1 | ERROR   | An error occurred during processing; checking has been aborted. The error message was: Trying to access array offset on value of type bool
    |         | in path/to/WordPress/Sniffs/Security/EscapeOutputSniff.php on line 198 (Internal.Exception)
```
@jrfnl jrfnl requested a review from a team as a code owner July 22, 2020 21:03
Copy link
Contributor

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

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

Ouch - what an awkward combination of reasons. Thanks for reviewing and getting to the bottom of it :-)

@GaryJones GaryJones merged commit 26628f7 into develop Jul 22, 2020
@GaryJones GaryJones deleted the fix/485-revert-and-fix-properly branch July 22, 2020 22:17
@GaryJones GaryJones added this to the 2.2.0 milestone Jul 22, 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.

2 participants