Visitar URL original
[4.x] Parse language metadata files without warnings or network access by Hackwar · Pull Request #65 · joomla-framework/language · GitHub
Skip to content

[4.x] Parse language metadata files without warnings or network access - #65

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-metadata-xml-errors
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-metadata-xml-errors

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

LanguageHelper::parseXmlLanguageFile() loaded the metadata file of a language pack with a plain simplexml_load_file(). Reproduced: a malformed file emits a series of libxml warnings, and a well-formed <metafile> without a <metadata> child makes the foreach over null warn as well ("foreach() argument must be of type array|object").

The method now collects libxml errors internally (restoring the previous libxml_use_internal_errors() setting and clearing the errors afterwards), passes LIBXML_NONET so parsing never touches the network, and returns null for a file without <metadata>. Before, that case returned an empty array, which getMetadata() and parseLanguageFiles() already treated like null. External entities are not expanded by libxml ≥ 2.9 anyway, so this is hardening rather than an XXE fix.

Testing Instructions

New tests/MetadataXmlTest.php with the fixtures tests/data/metadata/broken.xml and no-metadata.xml (new files, so they do not conflict with #59): both return null without warnings, the libxml state is restored, and a valid file is still read. The two malformed-file tests fail without the change in src/LanguageHelper.php; the whole suite passes with it (php vendor/bin/phpunit).

Documentation Changes Required

docs/overview.md: a new paragraph at the end of "Things to know before you build on this" on malformed metadata files.

🤖 Generated with Claude Code

parseXmlLanguageFile() loaded metadata files from language packs with
plain simplexml_load_file(): malformed XML emitted a series of libxml
warnings, and a metafile without a <metadata> element made the foreach
over null warn as well. libxml errors are now collected internally and
cleared, LIBXML_NONET forbids network access while parsing, and a file
without <metadata> is treated as not being a metadata file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant