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:
parent
08a069555f
commit
0b0f2e1b2d
3 changed files with 16 additions and 2 deletions
|
@ -665,8 +665,8 @@ class Book {
|
||||||
*/
|
*/
|
||||||
coverUrl() {
|
coverUrl() {
|
||||||
var retrieved = this.loaded.cover.
|
var retrieved = this.loaded.cover.
|
||||||
then((url) => {
|
then(() => {
|
||||||
if(this.archived) {
|
if(this.archived && this.cover) {
|
||||||
return this.archive.createUrl(this.cover);
|
return this.archive.createUrl(this.cover);
|
||||||
}else{
|
}else{
|
||||||
return this.cover;
|
return this.cover;
|
||||||
|
|
14
test/book.js
14
test/book.js
|
@ -50,4 +50,18 @@ describe('Book', function() {
|
||||||
assert( /^blob:http:\/\/localhost:9876\/[^\/]+$/.test(coverUrl), "cover url is available and a blob: url" );
|
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
BIN
test/fixtures/alice_without_cover.epub
vendored
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue