Skip to content

Commit

Permalink
Merge pull request #13 from pxlrbt/feature/fix-display-filename
Browse files Browse the repository at this point in the history
Sanitize filename
  • Loading branch information
pxlrbt authored Dec 7, 2023
2 parents 791d3da + 8e9d855 commit 6c34cdc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Concerns/CanBeRendered.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ public function stream()

public function download(?string $filename = null)
{
$filename = $filename ?? $this->displayFilename();

// Remove all characters that are not the separator, letters, numbers, or whitespace
$sanitizedFilename = preg_replace('![^'.preg_quote('-').'\pL\pN\s]+!u', '', $filename);

return response()->streamDownload(function () {
echo $this->driver()->getData($this);
},
$filename ?? $this->displayFilename(),
$sanitizedFilename,
['Content-Type' => 'application/pdf']
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Pdfable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Illuminate\Contracts\View\View;
use pxlrbt\LaravelPdfable\Layout\Page;

abstract class Pdfable implements Renderable, ShouldQueue, Attachable
abstract class Pdfable implements Attachable, Renderable, ShouldQueue
{
use Concerns\CanAccessPropertiesAndMethods;
use Concerns\CanBeAttached;
Expand Down

0 comments on commit 6c34cdc

Please sign in to comment.