1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +02:00

Bugfix calling coverUrl throws error on book without cover

When calling coverUrl on a book that has no cover a error is thrown

> TypeError: Cannot read property 'substr' of undefined

This is because Archive.getBlob is called with this.cover which is
undefined.
This commit is contained in:
Christiaan Baartse 2020-05-22 11:15:15 +02:00
parent 08a069555f
commit 0b0f2e1b2d
3 changed files with 16 additions and 2 deletions

View file

@ -665,8 +665,8 @@ class Book {
*/
coverUrl() {
var retrieved = this.loaded.cover.
then((url) => {
if(this.archived) {
then(() => {
if(this.archived && this.cover) {
return this.archive.createUrl(this.cover);
}else{
return this.cover;

View file

@ -50,4 +50,18 @@ describe('Book', function() {
assert( /^blob:http:\/\/localhost:9876\/[^\/]+$/.test(coverUrl), "cover url is available and a blob: url" );
});
});
describe('Archived epub without cover', function() {
var book = new Book("/fixtures/alice_without_cover.epub");
it('should open a archived epub', async function() {
await book.opened
assert.equal(book.isOpen, true, "book is opened");
assert(book.archive, "book is unarchived");
});
it('should have a empty coverUrl', async function() {
let coverUrl = await book.coverUrl()
assert.equal(coverUrl, undefined, "cover url should be undefined" );
});
});
});

BIN
test/fixtures/alice_without_cover.epub vendored Normal file

Binary file not shown.