Skip to content

Commit

Permalink
Escape header values
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo committed Sep 24, 2015
1 parent 34aeb3f commit bcdf951
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/TarStreamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ public function __construct($options = []){
* @param string $contentType Content mime type to be set (optional, default 'application/x-tar')
*/
public function sendHeaders($archiveName = 'archive.tar', $contentType = 'application/x-tar'){
$encodedArchiveName = rawurlencode($archiveName);
if (headers_sent($headerFile, $headerLine)){
die(
"<p><strong>Error:</strong> Unable to send file " .
"$archiveName. HTML Headers have already been sent from " .
"$encodedArchiveName. HTML Headers have already been sent from " .
"<strong>$headerFile</strong> in line <strong>$headerLine" .
"</strong></p>"
);
Expand All @@ -52,7 +53,7 @@ public function sendHeaders($archiveName = 'archive.tar', $contentType = 'applic
if (!empty($buffer)){
die(
"\n<p><strong>Error:</strong> Unable to send file " .
"<strong>$archiveName.epub</strong>. Output buffer " .
"<strong>$encodedArchiveName</strong>. Output buffer " .
"already contains text (typically warnings or errors).</p>"
);
}
Expand All @@ -69,8 +70,9 @@ public function sendHeaders($archiveName = 'archive.tar', $contentType = 'applic
'Content-Transfer-Encoding' => 'binary',
];

foreach ($headers as $key => $val){
header("$key: $val");
foreach ($headers as $key => $value){
$encodedValue = rawurlencode($value);
header("$key: $encodedValue");
}
}

Expand Down

0 comments on commit bcdf951

Please sign in to comment.