diff --git a/NEWS b/NEWS index ca9858374f3ab..228a0f7b20a9d 100644 --- a/NEWS +++ b/NEWS @@ -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) diff --git a/UPGRADING b/UPGRADING index 9c0909963aeb8..c757eda334e50 100644 --- a/UPGRADING +++ b/UPGRADING @@ -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. diff --git a/ext/dom/document.c b/ext/dom/document.c index 6c318bbb3dd2e..6268f9b687594 100644 --- a/ext/dom/document.c +++ b/ext/dom/document.c @@ -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(); diff --git a/ext/dom/tests/modern/xml/XMLDocument_fromString_03.phpt b/ext/dom/tests/modern/xml/XMLDocument_fromString_03.phpt index 359f7086efcea..2c2bb2ba33a3e 100644 --- a/ext/dom/tests/modern/xml/XMLDocument_fromString_03.phpt +++ b/ext/dom/tests/modern/xml/XMLDocument_fromString_03.phpt @@ -6,7 +6,7 @@ dom --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) diff --git a/ext/dom/tests/xml_parsing_LIBXML_RECOVER.phpt b/ext/dom/tests/xml_parsing_LIBXML_RECOVER.phpt new file mode 100644 index 0000000000000..89e693d47565d --- /dev/null +++ b/ext/dom/tests/xml_parsing_LIBXML_RECOVER.phpt @@ -0,0 +1,23 @@ +--TEST-- +XML parsing with LIBXML_RECOVER +--EXTENSIONS-- +dom +--FILE-- +loadXML('', options: LIBXML_RECOVER); +echo $dom->saveXML(); + +$dom = DOM\XMLDocument::createFromString('', options: LIBXML_RECOVER); +echo $dom->saveXML(), "\n"; + +?> +--EXPECTF-- +Warning: DOMDocument::loadXML(): %s + + + +Warning: DOM\XMLDocument::createFromString(): %s + + diff --git a/ext/dom/xml_document.c b/ext/dom/xml_document.c index c45e2ccfda014..3e50f3caa19a5 100644 --- a/ext/dom/xml_document.c +++ b/ext/dom/xml_document.c @@ -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 @@ -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, " diff --git a/ext/libxml/libxml.stub.php b/ext/libxml/libxml.stub.php index b60a6272503fe..ac9220c4f1d0e 100644 --- a/ext/libxml/libxml.stub.php +++ b/ext/libxml/libxml.stub.php @@ -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 diff --git a/ext/libxml/libxml_arginfo.h b/ext/libxml/libxml_arginfo.h index 5373b5ea003c0..17128faa04699 100644 --- a/ext/libxml/libxml_arginfo.h +++ b/ext/libxml/libxml_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 98cdd082ed214f84fd741097dd58979accc37bff */ + * Stub hash: 08e4e3f10ba89430292831f50c4760a362593282 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_libxml_set_streams_context, 0, 1, IS_VOID, 0) ZEND_ARG_INFO(0, context) @@ -59,6 +59,7 @@ static void register_libxml_symbols(int module_number) REGISTER_LONG_CONSTANT("LIBXML_VERSION", LIBXML_VERSION, CONST_PERSISTENT); REGISTER_STRING_CONSTANT("LIBXML_DOTTED_VERSION", LIBXML_DOTTED_VERSION, CONST_PERSISTENT); REGISTER_STRING_CONSTANT("LIBXML_LOADED_VERSION", PHP_LIBXML_LOADED_VERSION, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("LIBXML_RECOVER", XML_PARSE_RECOVER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("LIBXML_NOENT", XML_PARSE_NOENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("LIBXML_DTDLOAD", XML_PARSE_DTDLOAD, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("LIBXML_DTDATTR", XML_PARSE_DTDATTR, CONST_PERSISTENT); diff --git a/ext/simplexml/tests/xml_parsing_LIBXML_RECOVER.phpt b/ext/simplexml/tests/xml_parsing_LIBXML_RECOVER.phpt new file mode 100644 index 0000000000000..cfeb8e0c7413f --- /dev/null +++ b/ext/simplexml/tests/xml_parsing_LIBXML_RECOVER.phpt @@ -0,0 +1,21 @@ +--TEST-- +XML parsing with LIBXML_RECOVER +--EXTENSIONS-- +simplexml +--FILE-- +', options: LIBXML_RECOVER)); + +?> +--EXPECTF-- +Warning: simplexml_load_string(): %s + +Warning: simplexml_load_string(): in %s on line %d + +Warning: simplexml_load_string(): ^ in %s on line %d +object(SimpleXMLElement)#1 (1) { + ["child"]=> + object(SimpleXMLElement)#2 (0) { + } +}