Skip to content

Generic/LowercasedFilename: sniff doesn't handle non-ANSII characters properly #682

Open
@rodrigoprimo

Description

@rodrigoprimo

Describe the bug

While working on improving code coverage for the Generic.Files.LowercasedFilename sniff (#681), I noticed that it fails to properly handle file names that contain uppercase non-ANSII characters as it uses strtolower() to check if the filename is all lowercase. strtolower() ignores non-ANSII characters.

$lowercaseFilename = strtolower($filename);

Code sample

<?php

To reproduce

Steps to reproduce the behavior:

  1. Create a file called tÉst.php with the code sample above.
  2. Run phpcs tÉst.php --standard=Generic --sniffs=Generic.Files.LowercasedFilename
  3. No error message is displayed.

Expected behavior

PHPCS should display the following error message:

----------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------
 1 | ERROR | Filename "tÉst.php" doesn't match the expected filename "tést.php"
----------------------------------------------------------------------------------

Versions (please complete the following information)

Operating System Ubuntu 24.04
PHP version 8.3
PHP_CodeSniffer version master
Standard Generic
Install type git clone

Please confirm

  • I have searched the issue list and am not opening a duplicate issue.
  • I have read the Contribution Guidelines and this is not a support question.
  • I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
  • I have verified the issue still exists in the master branch of PHP_CodeSniffer.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions