ComposerRequireChecker: Warning: preg_match(): Compilation failed: unrecognized character
For select repos, when I run the tool from a PHAR file on Windows 10, I receive the following PHP warning (x 40 or so)😐
Warning: preg_match(): Compilation failed: unrecognized character follows \ at offset 19 in phar://path/to/composer-require-checker.4.7.0.phar/src/ComposerRequireChecker/FileLocator/LocateAllFilesByExtension.php on line 56
Runtime details:
> composer-require-check check composer.json
PHP 8.2.8 (cli) (built: Jul 4 2023 15:53:15) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.8, Copyright (c) Zend Technologies
with Zend OPcache v8.2.8, Copyright (c), by Zend Technologies
ComposerRequireChecker 4.7.0@a80a012ba94d5423b02754b2816960a74d3d4f3f
Warning: preg_match(): Compilation failed: unrecognized character follows \ at offset 19 in phar://path/to/composer-require-checker.4.7.0.phar/src/ComposerRequireChecker/FileLocator/LocateAllFilesByExtension.php on line 56
I suspect the issue is with the regex escaping of paths in a blacklist, but not sure how to debug this with just a PHAR file.
Neither the path to the repo, nor the path to the PHAR file contains spaces in any of the directory paths
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 15 (6 by maintainers)
I’ve downloaded an evaluation virtual machine from Microsoft and reproduced the bug there. From what I can tell, the problem is here https://github.com/maglnet/ComposerRequireChecker/blob/451403683a2a6509500b619e9eb59037579cdc7f/src/ComposerRequireChecker/FileLocator/LocateAllFilesByExtension.php#L82-L89 where we replace the safe-for-regular-expressions
$dirSep
with a plainDIRECTORY_SEPARATOR
.I’ve unwrapped this complex one-liner into its separate statements, and when I comment out this line:
$path = preg_replace('{' . $dirSep . '+}', DIRECTORY_SEPARATOR, $path);
it all seems to work as expected on Windows and Linux.I’m working through the testsuite now and will open a pull request shortly.
Thank you for your input, the base path really does not look suspicious 😀 I’ll see if I can reproduce this somehow.