Accept documents that only produce warnings and fix leak#159
Open
shunkica wants to merge 2 commits into
Open
Conversation
XmlDocument.fromString/fromBuffer rejected well-formed documents whenever libxml2 emitted any diagnostic, including warning-level ones, and leaked the parsed C document on that throw. Two defects in parse() (src/document.mts): 1. Failure was decided by presence of any diagnostic (errDetails.length > 0), never by severity, so warnings (XML_ERR_WARNING = 1) were treated as fatal. Now failure is gated on level >= XML_ERR_ERROR (2), so warnings pass and error/fatal diagnostics (incl. XML_PARSE_DTDVALID validity errors) still throw. 2. The pre-throw cleanup guard was inverted (`if (!xml) xmlFreeDoc(xml)`): it freed only when the pointer was null and skipped freeing a real document, which then leaked since the throw precedes wrapper/finalizer creation. The guard is corrected to free the produced document before throwing. To make surviving warnings observable (they were silently discarded), capture the diagnostic severity and expose non-fatal diagnostics on the parsed document: - XmlErrorStruct.level (xmlError offset 12) + ErrorDetail.level - XmlDocument.warnings: ErrorDetail[] (level-1 diagnostics; [] for clean parses) Existing details assertions updated for the new level field; adds tests for warning acceptance, warning surfacing, validity-error rejection, and no-leak.
|
Coverage after merging fix/parse-warning-severity-and-leak into master will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This was referenced Jul 24, 2026
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.
Fixes #158.
Changes
XmlErrorStruct.level(xmlErrorstruct offset 12)and a public
ErrorDetail.levelfield (1= warning,2= error,3=fatal);
errorCollectornow records it.parse()throws only when a diagnostic is>= XML_ERR_ERROR (2)or no document was produced. This keeps rejectinggenuine errors - including
XML_PARSE_DTDVALIDvalidity errors, whichleave the document well-formed (non-null) but must still fail.
throwing (e.g. a partial doc from
XML_PARSE_RECOVER).way to observe them. They are now exposed on the parsed document via a new
XmlDocument.warnings: ErrorDetail[]accessor - the sameErrorDetailshapeused by
XmlParseError.details, mirrored onto the success path. It is[]for clean parses and for documents created with
XmlDocument.create().