Skip to content

Commit

Permalink
Fix "Uncaught TypeError: linkparts.shift is not a function" error (#41)
Browse files Browse the repository at this point in the history
* Fix crash on empty chapters

* Fix crash on some links

* Fix for empty chapters
  • Loading branch information
christianroy authored and julien-c committed Jul 12, 2019
1 parent 124d461 commit d117153
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,8 @@ class EPub extends EventEmitter {

// replace links
str = str.replace(/(\shref\s*=\s*["']?)([^"'\s>]*?)(["'\s>])/g, (function (o, a, b, c) {
var linkparts = b && b.split("#"),
link = path.concat([(linkparts.shift() || "")]).join("/").trim(),
var linkparts = b && b.split("#");
var link = linkparts.length ? path.concat([(linkparts.shift() || "")]).join("/").trim() : '',
element;

for (i = 0, len = keys.length; i < len; i++) {
Expand Down Expand Up @@ -718,7 +718,11 @@ class EPub extends EventEmitter {
return;
}

var str = data.toString("utf-8");
var str = "";
if (data) {
str = data.toString("utf-8");
};


callback(null, str);

Expand Down

0 comments on commit d117153

Please sign in to comment.