Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Formats/Mobi/MobiModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function toEbook(): Ebook
$this->ebook->setAuthor(new BookAuthor($author));
}

foreach ($this->parser->get(MobiReader::ISBN_104, true) as $isbn) {
foreach ($this->parser->get(MobiReader::ISBN_104, true) ?? [] as $isbn) {
$this->ebook->setIdentifier(new BookIdentifier($isbn));
}

Expand All @@ -61,7 +61,7 @@ public function toEbook(): Ebook
$description = $this->parser->get(MobiReader::DESCRIPTION_103);
$this->ebook->setDescription($description);

foreach ($this->parser->get(MobiReader::SUBJECT_105, true) as $value) {
foreach ($this->parser->get(MobiReader::SUBJECT_105, true) ?? [] as $value) {
$this->ebook->setTag($value);
}

Expand Down
5 changes: 5 additions & 0 deletions src/Formats/Mobi/Parser/MobiParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@
length: $this->stream->binaryToDecimal($this->stream->read(4)),
);

if ($record->length <= 8) {
$this->errors[] = "EXTH record length invalid: {$record->length} (expected > 8)";
continue;

Check warning on line 126 in src/Formats/Mobi/Parser/MobiParser.php

View check run for this annotation

Codecov / codecov/patch

src/Formats/Mobi/Parser/MobiParser.php#L125-L126

Added lines #L125 - L126 were not covered by tests
}

$record->data = $this->stream->read($record->length - 8);
$this->exthHeader->records[] = $record;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Models/BookIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(

private function parseScheme(?string $scheme = null): string
{
$isValidInt = is_int($this->value) || ctype_digit($this->value);
$isValidInt = $this->value !== null && (is_int($this->value) || ctype_digit($this->value));
$isValidIsbn = false;
if ($isValidInt && $this->isIsbn()) {
$scheme = $this->parseIsbn();
Expand Down Expand Up @@ -50,7 +50,7 @@ private function parseScheme(?string $scheme = null): string
private function isIsbn(): bool
{
$regex = '/^(?=(?:\D*\d){10}(?:(?:\D*\d){3})?$)[\d-]+$/';
if (preg_match($regex, $this->value, $matches)) {
if ($this->value !== null && preg_match($regex, $this->value, $matches)) {
return true;
}

Expand All @@ -60,7 +60,7 @@ private function isIsbn(): bool
private function isDoi(): bool
{
$regex = '/^10.\d{4,9}\/[-._;()\/:A-Z0-9]+$/i';
if (preg_match($regex, $this->value, $matches)) {
if ($this->value !== null && preg_match($regex, $this->value, $matches)) {
return true;
}

Expand All @@ -70,12 +70,12 @@ private function isDoi(): bool
private function isUuid(): bool
{
$regex = '/^urn:uuid:([a-f\d]{8}(-[a-f\d]{4}){3}-[a-f\d]{12})$/i';
if (preg_match($regex, $this->value, $matches)) {
if ($this->value !== null && preg_match($regex, $this->value, $matches)) {
return true;
}

$regex = '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i';
if (preg_match($regex, $this->value, $matches)) {
if ($this->value !== null && preg_match($regex, $this->value, $matches)) {
return true;
}

Expand Down
Loading