Skip to content

Fix duplicate xmlns attributes and silent XML parse failures in MetronInfo/ComicInfo#239

Merged
bpepple merged 2 commits into
masterfrom
238-metroninfowrite_xml-produces-invalid-xml-with-duplicate-xmlnsxsixsischemalocation-attributes-when-merging-into-an-existing-metroninfoxml
Jul 19, 2026
Merged

Fix duplicate xmlns attributes and silent XML parse failures in MetronInfo/ComicInfo#239
bpepple merged 2 commits into
masterfrom
238-metroninfowrite_xml-produces-invalid-xml-with-duplicate-xmlnsxsixsischemalocation-attributes-when-merging-into-an-existing-metroninfoxml

Conversation

@bpepple

@bpepple bpepple commented Jul 19, 2026

Copy link
Copy Markdown
Member

Summary

  • Fix MetronInfo._get_root() producing invalid XML (duplicate xmlns:xsi and xsi:schemaLocation attributes) when merging metadata into an existing MetronInfo.xml. ElementTree parses an existing xsi:schemaLocation attribute into Clark notation rather than its literal form, so re-adding the canonical attribute left both present, and ET.tostring() auto-generated a second xmlns:xsi declaration for the Clark-notation one.
  • metadata_from_string() (MetronInfo/ComicInfo) and BaseMetadataHandler.read_xml() now raise XmlError on unparseable XML instead of silently swallowing the failure and returning an empty Metadata(), which hid real corruption from callers.

Behavior change

Callers that invoke MetronInfo.metadata_from_string(), ComicInfo.metadata_from_string(), or BaseMetadataHandler.read_xml() directly with malformed XML will now see an XmlError raised instead of getting back an empty Metadata(). Code that doesn't wrap these calls in a try/except will need to handle this.

Comic users are unaffected: Comic._parse_metadata() already wraps these calls in try/except Exception and logs via logger.exception(...), so Comic.read_metadata() continues to degrade gracefully to an empty Metadata() on parse failure — it now also logs a clearer error.

Fixes #238

bpepple added 2 commits July 19, 2026 14:30
…tronInfo.xml

ElementTree parses an existing xsi:schemaLocation attribute into Clark notation rather than its literal form, so re-adding the canonical attribute in _get_root() left both present and caused ET.tostring() to emit a second, auto-generated xmlns:xsi declaration. Strip any existing XSI-namespaced attribute before re-adding the canonical one.

Fixes #238
metadata_from_string() and read_xml() previously caught ParseError and returned an empty Metadata(), hiding real corruption from callers that use MetronInfo/ComicInfo/BaseMetadataHandler directly. Comic already wraps these calls and logs the exception, so this only changes behavior for direct API consumers, who now get a signal instead of silent data loss.
@bpepple bpepple self-assigned this Jul 19, 2026
@bpepple bpepple added the bug Something isn't working label Jul 19, 2026
@bpepple
bpepple merged commit a82e5f7 into master Jul 19, 2026
11 checks passed
@bpepple
bpepple deleted the 238-metroninfowrite_xml-produces-invalid-xml-with-duplicate-xmlnsxsixsischemalocation-attributes-when-merging-into-an-existing-metroninfoxml branch July 19, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MetronInfo.write_xml produces invalid XML with duplicate xmlns:xsi/xsi:schemaLocation attributes when merging into an existing MetronInfo.xml

1 participant