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

Fixed pattern replacements in Filter.php #602

Closed
wants to merge 1 commit into from

Conversation

arturm11
Copy link

@arturm11 arturm11 commented Aug 28, 2024

Fixed bad pattern replacements. Eliminates warnings when used as PHP Sniffer extension in VSCode.

Description

If full Windows path is used as ignore filter in shouldIgnorePath() function, then conversion to PREG pattern was buggy.
Windows backslash separator should be converted into double backslash (escaped backslash) AND Linux slash separator should be converted into double backslash.

Suggested changelog entry

Add backslash into double backslash replacement for Windows.

Related issues/external references

PHP Sniffer extension for VSCode generates warnings on Windows without this fix.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.

Fixed bad pattern replacements. Eliminates warnings when used as PHP Sniffer extension in VSCode.
@jrfnl
Copy link
Member

jrfnl commented Aug 28, 2024

@arturm11 Thank you for this PR.

I've been able to reproduce the issue with PHPCS itself via the command line using something along the lines of:

phpcs --ignore=D:\path\to\PHP_CodeSniffer\src\Tokenizers\CSS.php

which results in a:

Warning: preg_match(): Compilation failed: unknown property after \P or \p at offset * in D:\path\to\PHP_CodeSniffer\src\Filters\Filter.php on line 278

And the change made in this PR fixes this. 👍

Before I can accept the PR, could you please have a look at the third checklist item in the "PR checklist" ?

I'd also like to see this change safeguarded via tests. There are some tests for the Filters in the tests/Core/Filters directory already. These could probably be expanded.

@arturm11
Copy link
Author

@jrfnl Now I am not sure. Please analyze Ignoring Files and Folders section in the wiki. It is stated, that filter can be treated as regular expression. Backslash character is special character for RE. Therefore Windows paths shouldn't be accepted and backslash should be converted to slash in Windows path on input.

@arturm11
Copy link
Author

arturm11 commented Sep 3, 2024

There is related bug in vscode-php-sniffer, so I close this request.
wongjn/vscode-php-sniffer#73

@jrfnl
Copy link
Member

jrfnl commented Sep 3, 2024

@arturm11 Thanks for getting back to me. Hope that bug gets fixed soon.

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