From 9f5d7343f79f6ff8295884df3229bc6696b4386c Mon Sep 17 00:00:00 2001
From: Michael Webster <miketwebster@gmail.com>
Date: Mon, 18 Jul 2022 10:43:47 -0400
Subject: [PATCH 03/10] epub: Fix index loading for certain documents - look
 for epub:type instead of epub:id.

Add a null check as well.

ref:
https://help.apple.com/itc/booksassetguide/en.lproj/itc0f175a5b9.html#apdd3c4c6d1c0904
https://idpf.org/epub/301/spec/epub-contentdocs-20140626.html#sec-xhtml-nav
Signed-off-by: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
---
 backend/epub/epub-document.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/backend/epub/epub-document.c b/backend/epub/epub-document.c
index 52530f4..385d2fe 100644
--- a/backend/epub/epub-document.c
+++ b/backend/epub/epub-document.c
@@ -1201,7 +1201,13 @@ setup_index_from_navfile(gchar *tocpath)
     GList *index = NULL;
     open_xml_document(tocpath);
     set_xml_root_node(NULL);
-    xmlNodePtr nav = xml_get_pointer_to_node((xmlChar*)"nav",(xmlChar*)"id",(xmlChar*)"toc");
+    xmlNodePtr nav = xml_get_pointer_to_node((xmlChar*)"nav",(xmlChar*)"type",(xmlChar*)"toc");
+
+    if (nav == NULL) {
+        xml_free_doc();
+        return NULL;
+    }
+
     xmlretval=NULL;
     xml_parse_children_of_node(nav,(xmlChar*)"ol", NULL,NULL);
     gchar *navdirend = g_strrstr(tocpath,"/");
-- 
2.39.2

