@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix an issue where Herald may fail to extract content from an empty commit

Summary:
Ref T13667. The Herald "content added" rule (and other similar rules) do not correctly extract content from empty commits.

When we load an empty raw diff, return an empty changed content map.

Ref T13588. Also fix some PHP8.1 null/string stuff

Test Plan:
- Ran "bin/repository reparse --publish <commit>", with an empty commit hash and a nonempty commit hash.
- Reviewed Herald transcripts for general sanity.

Maniphest Tasks: T13667, T13588

Differential Revision: https://secure.phabricator.com/D21761

+52 -22
+9
src/applications/diffusion/herald/HeraldCommitAdapter.php
··· 267 267 268 268 $raw = $diff_file->loadFileData(); 269 269 270 + // See T13667. This happens when a commit is empty and affects no files. 271 + if (!strlen($raw)) { 272 + return false; 273 + } 274 + 270 275 $parser = new ArcanistDiffParser(); 271 276 $changes = $parser->parseDiff($raw); 272 277 ··· 288 293 $this->commitDiff = $ex; 289 294 phlog($ex); 290 295 } 296 + } 297 + 298 + if ($this->commitDiff === false) { 299 + return array(); 291 300 } 292 301 293 302 if ($this->commitDiff instanceof Exception) {
+6 -1
src/applications/diffusion/query/pathchange/DiffusionPathChangeQuery.php
··· 88 88 $change->setFileType($raw_change['fileType']); 89 89 $change->setCommitIdentifier($commit->getCommitIdentifier()); 90 90 91 - $change->setTargetPath(ltrim($raw_change['targetPathName'], '/')); 91 + $target_path = $raw_change['targetPathName']; 92 + if ($target_path !== null) { 93 + $target_path = ltrim($target_path, '/'); 94 + } 95 + $change->setTargetPath($target_path); 96 + 92 97 $change->setTargetCommitIdentifier($raw_change['targetCommitIdentifier']); 93 98 94 99 $id = $raw_change['pathID'];
+9 -7
src/applications/diffusion/request/DiffusionRequest.php
··· 207 207 */ 208 208 private function initializeFromDictionary(array $data) { 209 209 $blob = idx($data, 'blob'); 210 - if (strlen($blob)) { 210 + if (phutil_nonempty_string($blob)) { 211 211 $blob = self::parseRequestBlob($blob, $this->supportsBranches()); 212 212 $data = $blob + $data; 213 213 } ··· 518 518 $result['path'] = $blob; 519 519 } 520 520 521 - $parts = explode('/', $result['path']); 522 - foreach ($parts as $part) { 523 - // Prevent any hyjinx since we're ultimately shipping this to the 524 - // filesystem under a lot of workflows. 525 - if ($part == '..') { 526 - throw new Exception(pht('Invalid path URI.')); 521 + if ($result['path'] !== null) { 522 + $parts = explode('/', $result['path']); 523 + foreach ($parts as $part) { 524 + // Prevent any hyjinx since we're ultimately shipping this to the 525 + // filesystem under a lot of workflows. 526 + if ($part == '..') { 527 + throw new Exception(pht('Invalid path URI.')); 528 + } 527 529 } 528 530 } 529 531
+2 -2
src/applications/macro/query/PhabricatorMacroQuery.php
··· 128 128 $this->authorPHIDs); 129 129 } 130 130 131 - if (strlen($this->nameLike)) { 131 + if (($this->nameLike !== null) && strlen($this->nameLike)) { 132 132 $where[] = qsprintf( 133 133 $conn, 134 134 'm.name LIKE %~', ··· 142 142 $this->names); 143 143 } 144 144 145 - if (strlen($this->namePrefix)) { 145 + if (($this->namePrefix !== null) && strlen($this->namePrefix)) { 146 146 $where[] = qsprintf( 147 147 $conn, 148 148 'm.name LIKE %>',
+1 -1
src/applications/passphrase/query/PassphraseCredentialQuery.php
··· 148 148 (int)$this->allowConduit); 149 149 } 150 150 151 - if (strlen($this->nameContains)) { 151 + if (phutil_nonempty_string($this->nameContains)) { 152 152 $where[] = qsprintf( 153 153 $conn, 154 154 'LOWER(c.name) LIKE %~',
+1 -1
src/applications/repository/query/PhabricatorRepositoryQuery.php
··· 633 633 $this->uuids); 634 634 } 635 635 636 - if (strlen($this->datasourceQuery)) { 636 + if (phutil_nonempty_string($this->datasourceQuery)) { 637 637 // This handles having "rP" match callsigns starting with "P...". 638 638 $query = trim($this->datasourceQuery); 639 639 if (preg_match('/^r/', $query)) {
+12 -10
src/applications/repository/storage/PhabricatorRepository.php
··· 281 281 282 282 public function getSubversionBaseURI($commit = null) { 283 283 $subpath = $this->getDetail('svn-subpath'); 284 - if (!strlen($subpath)) { 284 + 285 + if (!phutil_nonempty_string($subpath)) { 285 286 $subpath = null; 286 287 } 288 + 287 289 return $this->getSubversionPathURI($subpath, $commit); 288 290 } 289 291 ··· 301 303 302 304 $uri = rtrim($uri, '/'); 303 305 304 - if (strlen($path)) { 306 + if (phutil_nonempty_string($path)) { 305 307 $path = rawurlencode($path); 306 308 $path = str_replace('%2F', '/', $path); 307 309 $uri = $uri.'/'.ltrim($path, '/'); ··· 574 576 575 577 public function getURI() { 576 578 $short_name = $this->getRepositorySlug(); 577 - if (strlen($short_name)) { 579 + if (phutil_nonempty_string($short_name)) { 578 580 return "/source/{$short_name}/"; 579 581 } 580 582 581 583 $callsign = $this->getCallsign(); 582 - if (strlen($callsign)) { 584 + if (phutil_nonempty_string($callsign)) { 583 585 return "/diffusion/{$callsign}/"; 584 586 } 585 587 ··· 593 595 594 596 public function getCommitURI($identifier) { 595 597 $callsign = $this->getCallsign(); 596 - if (strlen($callsign)) { 598 + if (phutil_nonempty_string($callsign)) { 597 599 return "/r{$callsign}{$identifier}"; 598 600 } 599 601 ··· 736 738 return $this->getCommitURI($commit); 737 739 } 738 740 739 - if (strlen($path)) { 741 + if (phutil_nonempty_string($path)) { 740 742 $path = ltrim($path, '/'); 741 743 $path = str_replace(array(';', '$'), array(';;', '$$'), $path); 742 744 $path = phutil_escape_uri($path); 743 745 } 744 746 745 747 $raw_branch = $branch; 746 - if (strlen($branch)) { 748 + if (phutil_nonempty_string($branch)) { 747 749 $branch = phutil_escape_uri_path_component($branch); 748 750 $path = "{$branch}/{$path}"; 749 751 } 750 752 751 753 $raw_commit = $commit; 752 - if (strlen($commit)) { 754 + if (phutil_nonempty_string($commit)) { 753 755 $commit = str_replace('$', '$$', $commit); 754 756 $commit = ';'.phutil_escape_uri($commit); 755 757 } 756 758 757 - if (strlen($line)) { 759 + if (phutil_nonempty_string($line)) { 758 760 $line = '$'.phutil_escape_uri($line); 759 761 } 760 762 ··· 862 864 863 865 public function getDefaultBranch() { 864 866 $default = $this->getDetail('default-branch'); 865 - if (strlen($default)) { 867 + if (phutil_nonempty_string($default)) { 866 868 return $default; 867 869 } 868 870
+8
src/infrastructure/markup/PhabricatorMarkupEngine.php
··· 583 583 $engine->setConfig('viewer', $viewer); 584 584 585 585 foreach ($content_blocks as $content_block) { 586 + if ($content_block === null) { 587 + continue; 588 + } 589 + 590 + if (!strlen($content_block)) { 591 + continue; 592 + } 593 + 586 594 $engine->markupText($content_block); 587 595 $phids = $engine->getTextMetadata( 588 596 PhabricatorMentionRemarkupRule::KEY_MENTIONED,
+4
src/infrastructure/markup/render.php
··· 105 105 } 106 106 107 107 function phutil_escape_html($string) { 108 + if ($string === null) { 109 + return ''; 110 + } 111 + 108 112 if ($string instanceof PhutilSafeHTML) { 109 113 return $string; 110 114 } else if ($string instanceof PhutilSafeHTMLProducerInterface) {