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

Composer 2.3 PATH unavailable causing error with Preg::isMatch #10662

Closed
jasonvarga opened this issue Mar 25, 2022 · 1 comment
Closed

Composer 2.3 PATH unavailable causing error with Preg::isMatch #10662

jasonvarga opened this issue Mar 25, 2022 · 1 comment
Labels
Milestone

Comments

@jasonvarga
Copy link

In our CMS, Statamic, we use Composer within our admin panel to allow users to update via the browser.
We use Symfony Process to execute Composer commands using whatever composer binary is in the vendor directory.

When running Composer 2.3 (and composer/pcre 3) to perform a composer require, it fails with the following stack trace.

The actual command being run behind the scenes is:

/path/to/php -d memory_limit=-1 vendor/bin/composer --no-ansi require statamic/cms 3.3.2 --update-with-dependencies
./composer.json has been updated
Running composer update statamic/cms --with-dependencies

Fatal error: Uncaught TypeError: Composer\Pcre\Preg::isMatch(): Argument #2 ($subject) must be of type string, bool given, called in /Users/jason/Code/statamic/three/sandbox/vendor/composer/composer/src/Composer/EventDispatcher/EventDispatcher.php on line 580 and defined in /Users/jason/Code/statamic/three/sandbox/vendor/composer/pcre/src/Preg.php:233
Stack trace:
#0 /Users/jason/Code/statamic/three/sandbox/vendor/composer/composer/src/Composer/EventDispatcher/EventDispatcher.php(580): Composer\Pcre\Preg::isMatch('{(^|:)/Users/ja...', false)
#1 /Users/jason/Code/statamic/three/sandbox/vendor/composer/composer/src/Composer/EventDispatcher/EventDispatcher.php(188): Composer\EventDispatcher\EventDispatcher->ensureBinDirIsInPath()
#2 /Users/jason/Code/statamic/three/sandbox/vendor/composer/composer/src/Composer/EventDispatcher/EventDispatcher.php(122): Composer\EventDispatcher\EventDispatcher->doDispatch(Object(Composer\Script\Event))
#3 /Users/jason/Code/statamic/three/sandbox/vendor/composer/composer/src/Composer/Installer.php(269): Composer\EventDispatcher\EventDispatcher->dispatchScript('pre-update-cmd', true)
#4 /Users/jason/Code/statamic/three/sandbox/vendor/composer/composer/src/Composer/Command/RequireCommand.php(425): Composer\Installer->run()
#5 /Users/jason/Code/statamic/three/sandbox/vendor/composer/composer/src/Composer/Command/RequireCommand.php(288): Composer\Command\RequireCommand->doUpdate(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput), Object(Composer\IO\ConsoleIO), Array, 'require', 'require-dev')
#6 /Users/jason/Code/statamic/three/sandbox/vendor/symfony/console/Command/Command.php(291): Composer\Command\RequireCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /Users/jason/Code/statamic/three/sandbox/vendor/symfony/console/Application.php(989): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 /Users/jason/Code/statamic/three/sandbox/vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application->doRunCommand(Object(Composer\Command\RequireCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 /Users/jason/Code/statamic/three/sandbox/vendor/composer/composer/src/Composer/Console/Application.php(332): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 /Users/jason/Code/statamic/three/sandbox/vendor/symfony/console/Application.php(171): Composer\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /Users/jason/Code/statamic/three/sandbox/vendor/composer/composer/src/Composer/Console/Application.php(128): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /Users/jason/Code/statamic/three/sandbox/vendor/composer/composer/bin/composer(84): Composer\Console\Application->run()
#13 /Users/jason/Code/statamic/three/sandbox/vendor/bin/composer(117): include('/Users/jason/Co...')
#14 {main}
  thrown in /Users/jason/Code/statamic/three/sandbox/vendor/composer/pcre/src/Preg.php on line 233

The issue appears to be that Platform::getEnv('PATH') returns false in the browser (or at least in our implementation).

(On the command line, it gets the PATH just fine.)

Since adding the string typehint to Preg::isMatch() in this commit it now fails because false is being passed in.

Previously, I guess it would silently fail? I'm not sure what ensureBinDirIsInPath was attempting to do, but everything seemed fine before.

Please let me know what other information I can provide. Thanks!

@Seldaek
Copy link
Member

Seldaek commented Mar 29, 2022

Thanks for the report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants