Fix: Normalize plain text input across libxml versions#93
Open
GertjanRoke wants to merge 1 commit intoueberdosis:mainfrom
Open
Fix: Normalize plain text input across libxml versions#93GertjanRoke wants to merge 1 commit intoueberdosis:mainfrom
GertjanRoke wants to merge 1 commit intoueberdosis:mainfrom
Conversation
…ml versions DOMDocument::loadHTML() behaves differently across libxml versions when parsing plain text (no HTML tags): libxml 2.9.x wraps bare text in <p> tags while libxml 2.10+ does not. This caused setContent() to produce inconsistent JSON output depending on the server environment. Detect plain text input (no HTML tags) via strip_tags() and wrap it in <p> before passing to loadHTML(), ensuring consistent paragraph-wrapped output regardless of the underlying libxml version. Fixes ueberdosis#90 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DOMParseroutput when plain text (no HTML tags) is passed tosetContent(), caused by differingDOMDocument::loadHTML()behavior between libxml 2.9.x and 2.10+strip_tags()and wraps it in<p>before parsing, ensuring consistent paragraph-wrapped output regardless of libxml versionFixes #90
Context
DOMDocument::loadHTML()delegates to libxml2's HTML parser, whose behavior changed in libxml 2.10.0 (HTML5-conformant tokenizer). On older libxml, bare text inside<body>is automatically wrapped in<p>, while newer libxml leaves it as a raw text node. This causedEditor->setContent('Hello world')to produce different Tiptap JSON depending on the server's libxml version.The fix is minimal: before calling
loadHTML(), check if the input contains any HTML tags usingstrip_tags(). If not, wrap it in<p>tags to normalize behavior to match what Tiptap's browser editor produces.Test plan
'Hello world'produces paragraph-wrapped JSON&,<) is handled correctly'<p>Hello world</p>'is not double-wrapped🤖 Generated with Claude Code