Skip to content

Restore libxml error state after conversion#269

Open
OmeBlues wants to merge 1 commit intothephpleague:masterfrom
OmeBlues:fix-libxml-error-state
Open

Restore libxml error state after conversion#269
OmeBlues wants to merge 1 commit intothephpleague:masterfrom
OmeBlues:fix-libxml-error-state

Conversation

@OmeBlues
Copy link
Copy Markdown

@OmeBlues OmeBlues commented Feb 1, 2026

Summary

  • Restore previous libxml internal error state after HTML conversion
  • Add tests to ensure state is restored and unchanged when suppression is disabled

Testing

  • ./vendor/bin/phpunit (PHP 7.4.33)
  • ./vendor/bin/phpunit (PHP 8.0.30)
  • PHP >= 8.1: local failures in existing tests (XML header output; unrelated to this change)

Fixes #268

@colinodell colinodell requested a review from Copilot February 1, 2026 11:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes issue #268 by ensuring that libxml's internal error state is properly restored after HTML-to-Markdown conversion, preventing global state pollution that could affect other code using libxml.

Changes:

  • Captured and restored the previous libxml error state after HTML conversion
  • Added test coverage to verify state restoration when error suppression is enabled
  • Added test coverage to verify state remains unchanged when error suppression is disabled

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/HtmlConverter.php Modified createDOMDocument() to capture initial libxml error state and restore it in a finally block
tests/HtmlConverterTest.php Added two test methods to verify libxml error state handling with and without error suppression

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

libxml_use_internal_errors state not restored after conversion

2 participants