Ward against preg_replace_callback null return value in Strings::performWithEscapedBlocks
- Add logging to troubleshoot potential issue with regex - Address part of https://github.com/friendica/friendica/issues/12011#issuecomment-1335124938
This commit is contained in:
parent
3b3192933d
commit
e6f8b8c6e0
|
@ -23,6 +23,7 @@ namespace Friendica\Util;
|
||||||
|
|
||||||
use Friendica\Content\ContactSelector;
|
use Friendica\Content\ContactSelector;
|
||||||
use Friendica\Core\Logger;
|
use Friendica\Core\Logger;
|
||||||
|
use Friendica\Core\System;
|
||||||
use ParagonIE\ConstantTime\Base64;
|
use ParagonIE\ConstantTime\Base64;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -480,7 +481,7 @@ class Strings
|
||||||
|
|
||||||
$blocks = [];
|
$blocks = [];
|
||||||
|
|
||||||
$text = preg_replace_callback($regex,
|
$return = preg_replace_callback($regex,
|
||||||
function ($matches) use ($executionId, &$blocks) {
|
function ($matches) use ($executionId, &$blocks) {
|
||||||
$return = '«block-' . $executionId . '-' . count($blocks) . '»';
|
$return = '«block-' . $executionId . '-' . count($blocks) . '»';
|
||||||
|
|
||||||
|
@ -491,7 +492,11 @@ class Strings
|
||||||
$text
|
$text
|
||||||
);
|
);
|
||||||
|
|
||||||
$text = $callback($text) ?? '';
|
if (is_null($return)) {
|
||||||
|
Logger::warning('Received null value from preg_replace_callback', ['text' => $text, 'regex' => $regex, 'blocks' => $blocks, 'executionId' => $executionId, 'callstack' => System::callstack(10)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$text = $callback($return ?? $text) ?? '';
|
||||||
|
|
||||||
// Restore code blocks
|
// Restore code blocks
|
||||||
$text = preg_replace_callback('/«block-' . $executionId . '-([0-9]+)»/iU',
|
$text = preg_replace_callback('/«block-' . $executionId . '-([0-9]+)»/iU',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user