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