@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.

AphrontFileResponse: avoid alien usages of setDownload()

Summary:
I noticed that - historically - setDownload() could also be used with
false, true, or other weird values to activate a download filename.
So, this change continues to give full compatibility to PHP 8.1 but
with extra validations.

This also adds a bit of inline documentation to put this more explicit.

For more context see the previous version:

{5952b0a31b6aac0718bc23aefe43560b9bfe8cc5}

{96ae4ba13acbf0e2f8932e950a92af0495f034d7}

Ref T15190

Test Plan:
- Drop a file in a comment, click, download
- See that it still works

Reviewers: O1 Blessed Committers, Cigaryno, avivey

Reviewed By: O1 Blessed Committers, Cigaryno, avivey

Subscribers: avivey, speck, tobiaswiese, Matthew, Cigaryno

Maniphest Tasks: T15190

Differential Revision: https://we.phorge.it/D25113

+26 -1
+26 -1
src/aphront/response/AphrontFileResponse.php
··· 8 8 private $compressResponse; 9 9 10 10 private $mimeType; 11 + 12 + /** 13 + * Download filename 14 + * 15 + * This is NULL as default or a string. 16 + * 17 + * @var string|null 18 + */ 11 19 private $download; 20 + 12 21 private $rangeMin; 13 22 private $rangeMax; 14 23 private $allowOrigins = array(); ··· 18 27 return $this; 19 28 } 20 29 30 + /** 31 + * Set a download filename 32 + * 33 + * @param $download string 34 + * @return self 35 + */ 21 36 public function setDownload($download) { 37 + 38 + // Make sure we have a populated string 22 39 if (!phutil_nonempty_string($download)) { 23 40 $download = 'untitled'; 24 41 } 42 + 25 43 $this->download = $download; 26 44 return $this; 27 45 } 28 46 47 + /** 48 + * Get the download filename 49 + * 50 + * If this was never set, NULL is given. 51 + * 52 + * @return string|null 53 + */ 29 54 public function getDownload() { 30 55 return $this->download; 31 56 } ··· 113 138 $headers[] = array('Content-Length', $content_len); 114 139 } 115 140 116 - if (strlen($this->getDownload())) { 141 + if (phutil_nonempty_string($this->getDownload())) { 117 142 $headers[] = array('X-Download-Options', 'noopen'); 118 143 119 144 $filename = $this->getDownload();