Edit Book: Fix a crash in the Insert Link tool if one of the HTML files contains an empty id. Fixes #1580928 [id=""](https://bugs.launchpad.net/calibre/+bug/1580928)

This commit is contained in:
Kovid Goyal 2016-05-12 15:43:10 +05:30
parent 5c3e43da0f
commit 88ff4ae126

View File

@ -670,6 +670,8 @@ class InsertLink(Dialog):
ac = self.anchor_cache[name] = [] ac = self.anchor_cache[name] = []
for item in set(root.xpath('//*[@id]')) | set(root.xpath('//h:a[@name]', namespaces={'h':XHTML_NS})): for item in set(root.xpath('//*[@id]')) | set(root.xpath('//h:a[@name]', namespaces={'h':XHTML_NS})):
frag = item.get('id', None) or item.get('name') frag = item.get('id', None) or item.get('name')
if not frag:
continue
text = lead_text(item, num_words=4) text = lead_text(item, num_words=4)
ac.append((text, frag)) ac.append((text, frag))
ac.sort(key=lambda text_frag: primary_sort_key(text_frag[0])) ac.sort(key=lambda text_frag: primary_sort_key(text_frag[0]))