mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-21 22:32:41 +01:00
Fix PHP 8.1 "preg_match()" exception when pasting malformed Raw Diff into "Create Diff"
Summary: Entering a malformed string (like `"pHoRgE rOcKs!!"`) into the "Raw Diff" field, Arcanist's `tryMatchHeader()` function is first called in `$ok = $this->tryMatchHeader($patterns, $line, $match)` with a non-null `$line` value (the first line entered in the "Raw Diff" field) being passed. Afterwards, `tryMatchHeader()` is called for a second time after assigning `$line = $this->nextLineThatLooksLikeDiffStart()`. This time `$line` is null and a RuntimeException is thrown, as `tryMatchHeader()` calls `preg_match()` which does not accept passing null as the $subject string parameter in PHP 8.1. Thus add a `phutil_nonempty_string()` check if the `$subject` parameter (in this case, `$line`) is a non-empty string. Arcanist's `tryMatchHeader()` function is not called outside of the file in which it is defined. Thus catch the exception in the second call to `tryMatchHeader()` and not in the code of the `tryMatchHeader()` function itself. Closes T15338 Test Plan: After adding the additional check, `/differential/diff/create/` showed the expected `Diff Parse Exception` instead. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15338 Differential Revision: https://we.phorge.it/D25183
This commit is contained in:
parent
12484acfc8
commit
084303cd5f
1 changed files with 3 additions and 1 deletions
|
@ -263,7 +263,9 @@ final class ArcanistDiffParser extends Phobject {
|
||||||
// searching for "diff -r" or "diff --git" in the text.
|
// searching for "diff -r" or "diff --git" in the text.
|
||||||
$this->saveLine();
|
$this->saveLine();
|
||||||
$line = $this->nextLineThatLooksLikeDiffStart();
|
$line = $this->nextLineThatLooksLikeDiffStart();
|
||||||
if (!$this->tryMatchHeader($patterns, $line, $match)) {
|
if (!phutil_nonempty_string($line)) {
|
||||||
|
$failed_parse = true;
|
||||||
|
} else if (!$this->tryMatchHeader($patterns, $line, $match)) {
|
||||||
// Restore line before guessing to display correct error.
|
// Restore line before guessing to display correct error.
|
||||||
$this->restoreLine();
|
$this->restoreLine();
|
||||||
$failed_parse = true;
|
$failed_parse = true;
|
||||||
|
|
Loading…
Reference in a new issue