picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.81k stars 616 forks source link

PHP Fatal error: Uncaught TypeError: abs() #639

Closed mtharmer closed 2 years ago

mtharmer commented 2 years ago

Version: 2.1.4 PHP: 8.0

Issue: This error causes an internal server error unless the proposed solution is implemented. This was tested as a hotfix on my server and verified to resolve the issue.

Stacktrace:

PHP Fatal error:  Uncaught TypeError: abs(): Argument #1 ($num) must be of type int|float, string given in /path/to/vendor/symfony/yaml/Parser.php:532
Stack trace:
#0 /path/to/pico/vendor/symfony/yaml/Parser.php(532): abs()
#1 /path/to/pico/vendor/symfony/yaml/Parser.php(258): Symfony\Component\Yaml\Parser->parseValue()
#2 /path/to/pico/vendor/symfony/yaml/Parser.php(320): Symfony\Component\Yaml\Parser->doParse()
#3 /path/to/pico/vendor/symfony/yaml/Parser.php(246): Symfony\Component\Yaml\Parser->parseBlock()
#4 /path/to/pico/vendor/symfony/yaml/Parser.php(320): Symfony\Component\Yaml\Parser->doParse()
#5 /path/to/pico/vendor/symfony/yaml/Parser.php(246): Symfony\Component\Yaml\Parser->parseBlock()
#6 /path/to/pico/vendor/symfony/yaml/Parser.php(78): Symfony\Component\Yaml\Parser->doParse()
#7 /path/to/pico/vendor/picocms/pico/lib/Pico.php(1093): Symfony\Component\Yaml\Parser->parse()
#8 /path/to/pico/vendor/picocms/pico/lib/Pico.php(441): Pico->loadTheme()
#9 /path/to/pico/index.php(39): Pico->run()
#10 {main}
  thrown in /path/to/pico/vendor/symfony/yaml/Parser.php on line 532

Issue at vendor/symfony/yaml/Parser.php:532:

    return $this->parseBlockScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs($modifiers));

Proposed solution:

    return $this->parseBlockScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs((int) $modifiers));
PhrozenByte commented 2 years ago

If you're running PHP 8.0 it's better to upgrade to https://github.com/picocms/Pico/releases/tag/v3.0.0-alpha.2. Don't worry about the "alpha" status, it's as stable as Pico 2.1 and just updates some dependencies to better support PHP 8.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1: