Skip to content

Add LIBXML_RECOVER #13504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ PHP NEWS
. Added LDAP_OPT_X_TLS_PROTOCOL_MAX/LDAP_OPT_X_TLS_PROTOCOL_TLS1_3
constants. (StephenWall)

- LibXML:
. Added LIBXML_RECOVER constant. (nielsdos)

- MBString:
. Added mb_trim, mb_ltrim and mb_rtrim. (Yuya Hamada)

Expand Down
3 changes: 3 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ PHP 8.4 UPGRADE NOTES
. LDAP_OPT_X_TLS_PROTOCOL_MAX.
. LDAP_OPT_X_TLS_PROTOCOL_TLS1_3.

- LibXML:
. LIBXML_RECOVER.

- OpenSSL:
. X509_PURPOSE_OCSP_HELPER.
. X509_PURPOSE_TIMESTAMP_SIGN.
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ xmlDocPtr dom_document_parser(zval *id, dom_load_mode mode, const char *source,
resolve_externals = doc_props->resolveexternals;
keep_blanks = doc_props->preservewhitespace;
substitute_ent = doc_props->substituteentities;
recover = doc_props->recover;
recover = doc_props->recover || (options & XML_PARSE_RECOVER) == XML_PARSE_RECOVER;

xmlInitParser();

Expand Down
5 changes: 3 additions & 2 deletions ext/dom/tests/modern/xml/XMLDocument_fromString_03.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dom
<?php

$flags = [
LIBXML_NOENT, LIBXML_DTDLOAD, LIBXML_DTDATTR, LIBXML_DTDVALID, LIBXML_NOERROR, LIBXML_NOWARNING, LIBXML_NOBLANKS, LIBXML_XINCLUDE, LIBXML_NSCLEAN, LIBXML_NOCDATA, LIBXML_NONET, LIBXML_PEDANTIC, LIBXML_COMPACT, LIBXML_PARSEHUGE, LIBXML_BIGLINES
LIBXML_RECOVER, LIBXML_NOENT, LIBXML_DTDLOAD, LIBXML_DTDATTR, LIBXML_DTDVALID, LIBXML_NOERROR, LIBXML_NOWARNING, LIBXML_NOBLANKS, LIBXML_XINCLUDE, LIBXML_NSCLEAN, LIBXML_NOCDATA, LIBXML_NONET, LIBXML_PEDANTIC, LIBXML_COMPACT, LIBXML_PARSEHUGE, LIBXML_BIGLINES
];

try {
Expand All @@ -21,7 +21,8 @@ foreach ($flags as $flag) {

?>
--EXPECT--
DOM\XMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_NOENT, LIBXML_DTDLOAD, LIBXML_DTDATTR, LIBXML_DTDVALID, LIBXML_NOERROR, LIBXML_NOWARNING, LIBXML_NOBLANKS, LIBXML_XINCLUDE, LIBXML_NSCLEAN, LIBXML_NOCDATA, LIBXML_NONET, LIBXML_PEDANTIC, LIBXML_COMPACT, LIBXML_PARSEHUGE, LIBXML_BIGLINES)bool(true)
DOM\XMLDocument::createFromString(): Argument #2 ($options) contains invalid flags (allowed flags: LIBXML_RECOVER, LIBXML_NOENT, LIBXML_DTDLOAD, LIBXML_DTDATTR, LIBXML_DTDVALID, LIBXML_NOERROR, LIBXML_NOWARNING, LIBXML_NOBLANKS, LIBXML_XINCLUDE, LIBXML_NSCLEAN, LIBXML_NOCDATA, LIBXML_NONET, LIBXML_PEDANTIC, LIBXML_COMPACT, LIBXML_PARSEHUGE, LIBXML_BIGLINES)bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
Expand Down
23 changes: 23 additions & 0 deletions ext/dom/tests/xml_parsing_LIBXML_RECOVER.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
XML parsing with LIBXML_RECOVER
--EXTENSIONS--
dom
--FILE--
<?php

$dom = new DOMDocument;
$dom->loadXML('<root><child/>', options: LIBXML_RECOVER);
echo $dom->saveXML();

$dom = DOM\XMLDocument::createFromString('<root><child/>', options: LIBXML_RECOVER);
echo $dom->saveXML(), "\n";

?>
--EXPECTF--
Warning: DOMDocument::loadXML(): %s
<?xml version="1.0"?>
<root><child/></root>

Warning: DOM\XMLDocument::createFromString(): %s
<?xml version="1.0" encoding="UTF-8"?>
<root><child/></root>
4 changes: 3 additions & 1 deletion ext/dom/xml_document.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

static bool check_options_validity(uint32_t arg_num, zend_long options)
{
const zend_long VALID_OPTIONS = XML_PARSE_NOENT
const zend_long VALID_OPTIONS = XML_PARSE_RECOVER
| XML_PARSE_NOENT
| XML_PARSE_DTDLOAD
| XML_PARSE_DTDATTR
| XML_PARSE_DTDVALID
Expand All @@ -42,6 +43,7 @@ static bool check_options_validity(uint32_t arg_num, zend_long options)
| XML_PARSE_BIG_LINES;
if ((options & ~VALID_OPTIONS) != 0) {
zend_argument_value_error(2, "contains invalid flags (allowed flags: "
"LIBXML_RECOVER, "
"LIBXML_NOENT, "
"LIBXML_DTDLOAD, "
"LIBXML_DTDATTR, "
Expand Down
5 changes: 5 additions & 0 deletions ext/libxml/libxml.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
const LIBXML_LOADED_VERSION = UNKNOWN;

/**
* @var int
* @cvalue XML_PARSE_RECOVER
*/
const LIBXML_RECOVER = UNKNOWN;
/**
* @var int
* @cvalue XML_PARSE_NOENT
Expand Down
3 changes: 2 additions & 1 deletion ext/libxml/libxml_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions ext/simplexml/tests/xml_parsing_LIBXML_RECOVER.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
XML parsing with LIBXML_RECOVER
--EXTENSIONS--
simplexml
--FILE--
<?php

var_dump(simplexml_load_string('<root><child/>', options: LIBXML_RECOVER));

?>
--EXPECTF--
Warning: simplexml_load_string(): %s

Warning: simplexml_load_string(): <root><child/> in %s on line %d

Warning: simplexml_load_string(): ^ in %s on line %d
object(SimpleXMLElement)#1 (1) {
["child"]=>
object(SimpleXMLElement)#2 (0) {
}
}