Skip to content

Give FileFormat XML for XML files on every platform - #2009

Merged
rocky merged 2 commits into
Mathics3:masterfrom
tombouctou:fix-fileformat-xml
Oct 16, 2026
Merged

rocky merged 2 commits into
Mathics3:masterfrom
tombouctou:fix-fileformat-xml

Conversation

@tombouctou

Copy link
Copy Markdown
Collaborator

Without libmagic, FileFormat["ExampleData/InventionNo1.xml"] gives XSL on macOS, and test_FileFormat fails there.

Without libmagic, the type is guessed from the extension: .xml → application/xml → mimetypes.guess_extension("application/xml"). Without an /etc/mime.types file (as on macOS), Python returns .xsl for that, since it is the first extension registered for application/xml. With libmagic the MIME type is text/xml, which happens to map to .xml.

This maps application/xml and text/xml to XML explicitly before asking mimetypes. A unit test for filetype_from_mime_content checks it on every platform.

(The other two test_FileFormat cases, a ZIP stored as .mx and a JPEG stored as .txt, need libmagic for content detection; with brew install libmagic, as in the macOS CI workflow, they pass.)

🤖 Generated with Claude Code

Without libmagic, FileFormat["ExampleData/InventionNo1.xml"] gave
"XSL" on macOS: the extension guess gives "application/xml", and
mimetypes.guess_extension() maps that to ".xsl" when there is no
/etc/mime.types. Map the XML MIME types explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@mmatera mmatera left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rocky

rocky commented Oct 16, 2026

Copy link
Copy Markdown
Member

Thanks!

@rocky
rocky merged commit 10846ac into Mathics3:master Oct 16, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants