From b325304b6e52d291e6ae327e847624d1713db12e Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Fri, 2 Jun 2023 18:30:39 +0200 Subject: [PATCH] Fix PHP 8.1 null exceptions which block rendering tab panels on dashboards Summary: Passing null as input strings to `substr()` and `preg_match()` is deprecated in PHP 8. Thus do not call `substr()` when input is `null` and pass an empty string instead of `null` to `preg_match()`. (Not calling `preg_match()` at all here would lead to `Exception: Lexical error on line 1. Unrecognized text. ^`). Closes T15346 Test Plan: After applying these three changes and following the steps in T15346, tab on the dashboard displays "This tab panel does not have any tabs yet." as expected instead of the previous RuntimeException. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15346 Differential Revision: https://we.phorge.it/D25250 --- externals/jsonlint/src/Seld/JsonLint/JsonParser.php | 2 +- externals/jsonlint/src/Seld/JsonLint/Lexer.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/externals/jsonlint/src/Seld/JsonLint/JsonParser.php b/externals/jsonlint/src/Seld/JsonLint/JsonParser.php index 7100abfa..ed3106ea 100644 --- a/externals/jsonlint/src/Seld/JsonLint/JsonParser.php +++ b/externals/jsonlint/src/Seld/JsonLint/JsonParser.php @@ -481,7 +481,7 @@ class JsonLintJsonParser // UTF-8 ByteOrderMark sequence $bom = "\xEF\xBB\xBF"; - if (substr($input, 0, 3) === $bom) { + if ($input && (substr($input, 0, 3) === $bom)) { $this->parseError("BOM detected, make sure your input does not include a Unicode Byte-Order-Mark", array()); } } diff --git a/externals/jsonlint/src/Seld/JsonLint/Lexer.php b/externals/jsonlint/src/Seld/JsonLint/Lexer.php index 4197afe1..d002b580 100644 --- a/externals/jsonlint/src/Seld/JsonLint/Lexer.php +++ b/externals/jsonlint/src/Seld/JsonLint/Lexer.php @@ -94,7 +94,7 @@ class JsonLintLexer public function getUpcomingInput() { $next = $this->match; - if (strlen($next) < 20) { + if ($this->input !== null && strlen($next) < 20) { $next .= substr($this->input, 0, 20 - strlen($next)); } @@ -128,6 +128,9 @@ class JsonLintLexer $rules = $this->getCurrentRules(); $rulesLen = count($rules); + if (!isset($this->input)) { + $this->input = ''; + } for ($i=0; $i < $rulesLen; $i++) { if (preg_match($this->rules[$rules[$i]], $this->input, $match)) { preg_match_all('/\n.*/', $match[0], $lines);