1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-24 15:52:40 +01:00

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
This commit is contained in:
Andre Klapper 2024-01-13 11:20:58 +01:00
parent 6142fcd526
commit 6c7caf3572

View file

@ -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!"));
}