diff --git a/src/calibre/ebooks/oeb/polish/check/opf.py b/src/calibre/ebooks/oeb/polish/check/opf.py index 73844fd9d1..9fc8f32bd1 100644 --- a/src/calibre/ebooks/oeb/polish/check/opf.py +++ b/src/calibre/ebooks/oeb/polish/check/opf.py @@ -223,7 +223,7 @@ class MultipleCovers(BaseError): class NoUID(BaseError): HELP = xml(_( - 'The OPF must have a unique identifier, i.e. a element whose id is referenced' + 'The OPF must have an unique identifier, i.e. a element whose id is referenced' ' by the element')) INDIVIDUAL_FIX = _('Auto-generate a unique identifier') @@ -251,10 +251,18 @@ class NoUID(BaseError): class EmptyIdentifier(BaseError): HELP = xml(_('The element must not be empty.')) + INDIVIDUAL_FIX = _('Remove empty identifiers') def __init__(self, name, lnum): BaseError.__init__(self, _('Empty identifier element'), name, lnum) + def __call__(self, container): + for dcid in container.opf_xpath('/opf:package/opf:metadata/dc:identifier'): + if not dcid.text or not dcid.text.strip(): + container.remove_from_xml(dcid) + container.dirty(container.opf_name) + return True + class BadSpineMime(BaseError): @@ -387,8 +395,12 @@ def check_opf(container): errors.append(NookCover(container.opf_name, cover.sourceline)) uid = container.opf.get('unique-identifier', None) - if uid is None or not container.opf_xpath('/opf:package/opf:metadata/dc:identifier[@id=%r]' % uid): + if uid is None: errors.append(NoUID(container.opf_name)) + else: + dcid = container.opf_xpath('/opf:package/opf:metadata/dc:identifier[@id=%r]' % uid) + if not dcid or not dcid[0].text or not dcid[0].text.strip(): + errors.append(NoUID(container.opf_name)) for elem in container.opf_xpath('/opf:package/opf:metadata/dc:identifier'): if not elem.text or not elem.text.strip(): errors.append(EmptyIdentifier(container.opf_name, elem.sourceline))