mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 21:40:55 +01:00
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
This commit is contained in:
parent
d46aab8321
commit
0a82ccb8a4
1 changed files with 26 additions and 1 deletions
|
@ -8,7 +8,16 @@ final class AphrontFileResponse extends AphrontResponse {
|
|||
private $compressResponse;
|
||||
|
||||
private $mimeType;
|
||||
|
||||
/**
|
||||
* Download filename
|
||||
*
|
||||
* This is NULL as default or a string.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $download;
|
||||
|
||||
private $rangeMin;
|
||||
private $rangeMax;
|
||||
private $allowOrigins = array();
|
||||
|
@ -18,14 +27,30 @@ final class AphrontFileResponse extends AphrontResponse {
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a download filename
|
||||
*
|
||||
* @param $download string
|
||||
* @return self
|
||||
*/
|
||||
public function setDownload($download) {
|
||||
|
||||
// Make sure we have a populated string
|
||||
if (!phutil_nonempty_string($download)) {
|
||||
$download = 'untitled';
|
||||
}
|
||||
|
||||
$this->download = $download;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the download filename
|
||||
*
|
||||
* If this was never set, NULL is given.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDownload() {
|
||||
return $this->download;
|
||||
}
|
||||
|
@ -113,7 +138,7 @@ final class AphrontFileResponse extends AphrontResponse {
|
|||
$headers[] = array('Content-Length', $content_len);
|
||||
}
|
||||
|
||||
if (strlen($this->getDownload())) {
|
||||
if (phutil_nonempty_string($this->getDownload())) {
|
||||
$headers[] = array('X-Download-Options', 'noopen');
|
||||
|
||||
$filename = $this->getDownload();
|
||||
|
|
Loading…
Reference in a new issue