Skip to content

Commit 6c34cdc

Browse files
authored
Merge pull request #13 from pxlrbt/feature/fix-display-filename
Sanitize filename
2 parents 791d3da + 8e9d855 commit 6c34cdc

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Concerns/CanBeRendered.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ public function stream()
2121

2222
public function download(?string $filename = null)
2323
{
24+
$filename = $filename ?? $this->displayFilename();
25+
26+
// Remove all characters that are not the separator, letters, numbers, or whitespace
27+
$sanitizedFilename = preg_replace('![^'.preg_quote('-').'\pL\pN\s]+!u', '', $filename);
28+
2429
return response()->streamDownload(function () {
2530
echo $this->driver()->getData($this);
2631
},
27-
$filename ?? $this->displayFilename(),
32+
$sanitizedFilename,
2833
['Content-Type' => 'application/pdf']
2934
);
3035
}

src/Pdfable.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Illuminate\Contracts\View\View;
99
use pxlrbt\LaravelPdfable\Layout\Page;
1010

11-
abstract class Pdfable implements Renderable, ShouldQueue, Attachable
11+
abstract class Pdfable implements Attachable, Renderable, ShouldQueue
1212
{
1313
use Concerns\CanAccessPropertiesAndMethods;
1414
use Concerns\CanBeAttached;

0 commit comments

Comments
 (0)