From 6c7caf3572f487b74ab0e28d860a449cc9495e6a Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Sat, 13 Jan 2024 11:20:58 +0100 Subject: [PATCH] Correct manual upload of Differential patch with a leading BOM Summary: Strip a leading UTF-8 Byte Order Mark to avoid silently dropping the first file in a manually uploaded patch. This change only strips the UTF-8 BOM as UTF-8 is acceptable input. (Probably non-existing) handling of any other BOMs as first bytes in a diff remains unchanged. Closes T15452 Test Plan: Go to `/differential/diff/create/` and upload the test case in T15452 via `Raw Diff From File`. See two files listed on resulting page `/differential/diff/1/` instead of previously only one file. Optionally, confirm that byte length of `$diff` is three bytes less now (via `strlen($diff)`). Reviewers: O1 Blessed Committers, speck Reviewed By: O1 Blessed Committers, speck Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15452 Differential Revision: https://we.phorge.it/D25514 --- src/parser/ArcanistDiffParser.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/parser/ArcanistDiffParser.php b/src/parser/ArcanistDiffParser.php index 53a46a7a..f80917ed 100644 --- a/src/parser/ArcanistDiffParser.php +++ b/src/parser/ArcanistDiffParser.php @@ -187,6 +187,11 @@ final class ArcanistDiffParser extends Phobject { } public function parseDiff($diff) { + // Remove leading UTF-8 Byte Order Mark (BOM) + if (substr($diff, 0, 3) == pack('CCC', 0xEF, 0xBB, 0xBF)) { + $diff = substr($diff, 3); + } + if (!strlen(trim($diff))) { throw new Exception(pht("Can't parse an empty diff!")); }