Skip to content

Commit

Permalink
fix Zipper to allow unicode chars in file names
Browse files Browse the repository at this point in the history
  • Loading branch information
mikespub committed Sep 1, 2024
1 parent 0325541 commit 63801c5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/Output/Zipper.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public function checkFileList($entries)
continue;
}
//$name = basename($path);
// @todo use normalizeUtf8String() on author, series and title or not?
// Using {author} - {series} #{series_index} - {title} with .{format}
$author = $entry->book->getAuthorsName();
$name = explode(', ', $author)[0];
Expand All @@ -227,7 +228,8 @@ public function checkFileList($entries)
$name .= ' - ' . $entry->book->title;
$info = pathinfo($path);
$name .= '.' . $info['extension'];
$name = preg_replace('/[^\w\s\d\'\.\-\/_,#\[\]\(\)]/', '', $name);
// allow unicode characters here
$name = preg_replace('/[^\w\s\d\'\.\-\/_,#\[\]\(\)]/u', '', $name);
$this->fileList[$name] = $path;
}
if (count($this->fileList) < 1) {
Expand Down Expand Up @@ -267,14 +269,18 @@ public function isValidForExtraFiles($book)

/**
* Summary of download
* @param ?string $fileName
* @param bool $sendHeaders
* @return void
*/
public function download()
public function download($fileName = null, $sendHeaders = true)
{
$fileName ??= $this->fileName;

// keep it simple for now, and use the basic options
$zip = new ZipStream(
outputName: $this->fileName,
sendHttpHeaders: true,
outputName: $fileName,
sendHttpHeaders: $sendHeaders,
);
foreach ($this->fileList as $name => $path) {
$zip->addFileFromPath(
Expand Down

0 comments on commit 63801c5

Please sign in to comment.