Skip to content

Fix libxml error messages for codes 1 to 4 in xml_error_string() - #25843

Open
lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/xml-libxml-error-strings
Open

lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/xml-libxml-error-strings

Conversation

@lacatoire

@lacatoire lacatoire commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

With libxml2, entries 1 to 4 of error_mapping[] don't match libxml2's error codes, so an empty document (code 4) is reported as "Not well-formed (invalid token)". "Internal error" is restored at index 1 and the extra entry at index 4 is removed; codes 5 and above are unchanged.

To reproduce

$parser = xml_parser_create();
xml_parse($parser, '', true);
$code = xml_get_error_code($parser);
var_dump($code, xml_error_string($code));
for ($i = 1; $i <= 5; $i++) {
    echo $i, ': ', xml_error_string($i), "\n";
}

Before (PHP 8.4.28 and 8.5.13, libxml2 2.13.9):

int(4)
string(31) "Not well-formed (invalid token)"
1: No memory
2: Invalid document start
3: Empty document
4: Not well-formed (invalid token)
5: Invalid document end

After:

int(4)
string(14) "Empty document"
1: Internal error
2: No memory
3: Invalid document start
4: Empty document
5: Invalid document end

@devnexen

Copy link
Copy Markdown
Member

just saying it s the right direction, the test needs fixing though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants