Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 4 additions & 1 deletion ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,10 @@ xmlDocPtr dom_document_parser(zval *id, dom_load_mode mode, const char *source,
return(NULL);
}

(void) xmlSwitchToEncoding(ctxt, encoding);
if (encoding != NULL) {
/* Note: libxml 2.12+ doesn't handle NULL encoding well. */
(void) xmlSwitchToEncoding(ctxt, encoding);
}

/* If loading from memory, we need to set the base directory for the document */
if (mode != DOM_LOAD_FILE) {
Expand Down
4 changes: 4 additions & 0 deletions ext/dom/tests/DOMDocument_loadXML_error1.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
--TEST--
Test DOMDocument::loadXML() detects not-well formed XML
--SKIPIF--
<?php
if (LIBXML_VERSION >= 21200) die('skip libxml2 test variant for version < 2.12');
?>
--DESCRIPTION--
This test verifies the method detects an opening and ending tag mismatch
Environment variables used in the test:
Expand Down
26 changes: 26 additions & 0 deletions ext/dom/tests/DOMDocument_loadXML_error1_gte2_12.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
Test DOMDocument::loadXML() detects not-well formed XML
--SKIPIF--
<?php
if (LIBXML_VERSION < 21200) die('skip libxml2 test variant for version >= 2.12');
?>
--DESCRIPTION--
This test verifies the method detects an opening and ending tag mismatch
Environment variables used in the test:
- XML_FILE: the xml file to load
- LOAD_OPTIONS: the second parameter to pass to the method
- EXPECTED_RESULT: the expected result
--CREDITS--
Antonio Diaz Ruiz <dejalatele@gmail.com>
--EXTENSIONS--
dom
--ENV--
XML_FILE=/not_well_formed.xml
LOAD_OPTIONS=0
EXPECTED_RESULT=0
--FILE_EXTERNAL--
domdocumentloadxml_test_method.inc
--EXPECTF--
Warning: DOMDocument::load%r(XML){0,1}%r(): Opening and ending tag mismatch: title line 5 and book %s

Warning: DOMDocument::load%r(XML){0,1}%r(): %rexpected '>'|Opening and ending tag mismatch: book line (4|5) and books%r %s
2 changes: 1 addition & 1 deletion ext/dom/tests/DOMDocument_loadXML_error2_gte2_11.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test DOMDocument::loadXML() detects not-well formed XML
--SKIPIF--
<?php
if (LIBXML_VERSION < 21100) die('skip libxml2 test variant for version >= 2.11');
if (LIBXML_VERSION < 21100 || LIBXML_VERSION >= 21200) die('skip libxml2 test variant for version >= 2.11 && <= 2.12');
?>
--DESCRIPTION--
This test verifies the method detects attributes values not closed between " or '
Expand Down
30 changes: 30 additions & 0 deletions ext/dom/tests/DOMDocument_loadXML_error2_gte2_12.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
Test DOMDocument::loadXML() detects not-well formed XML
--SKIPIF--
<?php
if (LIBXML_VERSION < 21200) die('skip libxml2 test variant for version >= 2.12');
?>
--DESCRIPTION--
This test verifies the method detects attributes values not closed between " or '
Environment variables used in the test:
- XML_FILE: the xml file to load
- LOAD_OPTIONS: the second parameter to pass to the method
- EXPECTED_RESULT: the expected result
--CREDITS--
Antonio Diaz Ruiz <dejalatele@gmail.com>
--EXTENSIONS--
dom
--ENV--
XML_FILE=/not_well_formed2.xml
LOAD_OPTIONS=0
EXPECTED_RESULT=0
--FILE_EXTERNAL--
domdocumentloadxml_test_method.inc
--EXPECTF--
Warning: DOMDocument::loadXML(): AttValue: " or ' expected in Entity, line: 4 in %s on line %d

Warning: DOMDocument::loadXML(): internal error: xmlParseStartTag: problem parsing attributes in Entity, line: 4 in %s on line %d

Warning: DOMDocument::loadXML(): Couldn't find end of Start Tag book line 4 in Entity, line: 4 in %s on line %d

Warning: DOMDocument::loadXML(): Opening and ending tag mismatch: books line 3 and book in Entity, line: 7 in %s on line %d
4 changes: 4 additions & 0 deletions ext/dom/tests/DOMDocument_load_error1.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
--TEST--
Test DOMDocument::load() detects not-well formed XML
--SKIPIF--
<?php
if (LIBXML_VERSION >= 21200) die('skip libxml2 test variant for version < 2.12');
?>
--DESCRIPTION--
This test verifies the method detects an opening and ending tag mismatch
Environment variables used in the test:
Expand Down
26 changes: 26 additions & 0 deletions ext/dom/tests/DOMDocument_load_error1_gte2_12.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
Test DOMDocument::load() detects not-well formed XML
--SKIPIF--
<?php
if (LIBXML_VERSION < 21200) die('skip libxml2 test variant for version >= 2.12');
?>
--DESCRIPTION--
This test verifies the method detects an opening and ending tag mismatch
Environment variables used in the test:
- XML_FILE: the xml file to load
- LOAD_OPTIONS: the second parameter to pass to the method
- EXPECTED_RESULT: the expected result
--CREDITS--
Antonio Diaz Ruiz <dejalatele@gmail.com>
--EXTENSIONS--
dom
--ENV--
XML_FILE=/not_well_formed.xml
LOAD_OPTIONS=0
EXPECTED_RESULT=0
--FILE_EXTERNAL--
domdocumentload_test_method.inc
--EXPECTF--
Warning: DOMDocument::load%r(XML){0,1}%r(): Opening and ending tag mismatch: title line 5 and book %s

Warning: DOMDocument::load%r(XML){0,1}%r(): %rexpected '>'|Opening and ending tag mismatch: book line (4|5) and books%r %s
2 changes: 1 addition & 1 deletion ext/dom/tests/DOMDocument_load_error2_gte2_11.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test DOMDocument::load() detects not-well formed
--SKIPIF--
<?php
if (LIBXML_VERSION < 21100) die('skip libxml2 test variant for version >= 2.11');
if (LIBXML_VERSION < 21100 || LIBXML_VERSION >= 21200) die('skip libxml2 test variant for version >= 2.11');
?>
--DESCRIPTION--
This test verifies the method detects attributes values not closed between " or '
Expand Down
30 changes: 30 additions & 0 deletions ext/dom/tests/DOMDocument_load_error2_gte2_12.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
Test DOMDocument::load() detects not-well formed
--SKIPIF--
<?php
if (LIBXML_VERSION < 21200) die('skip libxml2 test variant for version >= 2.12');
?>
--DESCRIPTION--
This test verifies the method detects attributes values not closed between " or '
Environment variables used in the test:
- XML_FILE: the xml file to load
- LOAD_OPTIONS: the second parameter to pass to the method
- EXPECTED_RESULT: the expected result
--CREDITS--
Antonio Diaz Ruiz <dejalatele@gmail.com>
--EXTENSIONS--
dom
--ENV--
XML_FILE=/not_well_formed2.xml
LOAD_OPTIONS=0
EXPECTED_RESULT=0
--FILE_EXTERNAL--
domdocumentload_test_method.inc
--EXPECTF--
Warning: DOMDocument::load(): AttValue: " or ' expected in %s on line %d

Warning: DOMDocument::load(): internal error: xmlParseStartTag: problem parsing attributes in %s on line %d

Warning: DOMDocument::load(): Couldn't find end of Start Tag book line 4 in %s on line %d

Warning: DOMDocument::load(): Opening and ending tag mismatch: books line 3 and book in %s on line %d
6 changes: 6 additions & 0 deletions ext/dom/tests/DOMNode_isEqualNode.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
DOMNode::isEqualNode()
--EXTENSIONS--
dom
--SKIPIF--
<?php
if (LIBXML_VERSION >= 21200 && LIBXML_VERSION <= 21201) {
die("xfail Broken for libxml2 2.12.0 - 2.12.1 see https://gitlab.gnome.org/GNOME/libxml2/-/issues/634");
}
?>
--FILE--
<?php

Expand Down
20 changes: 13 additions & 7 deletions ext/libxml/libxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,11 @@ static void _php_libxml_free_error(void *ptr)
xmlResetError((xmlErrorPtr) ptr);
}

static void _php_list_set_error_structure(xmlErrorPtr error, const char *msg, int line, int column)
#if LIBXML_VERSION >= 21200
static void _php_list_set_error_structure(const xmlError *error, const char *msg, int line, int column)
#else
static void _php_list_set_error_structure(xmlError *error, const char *msg, int line, int column)
#endif
{
xmlError error_copy;
int ret;
Expand Down Expand Up @@ -824,7 +828,10 @@ PHP_LIBXML_API void php_libxml_pretend_ctx_error_ex(const char *file, int line,
if (!last->file) {
last->file = strdup(file);
}
/* Until there is a replacement */
ZEND_DIAGNOSTIC_IGNORED_START("-Wdeprecated-declarations")
xmlCopyError(last, &xmlLastError);
ZEND_DIAGNOSTIC_IGNORED_END
}
}
}
Expand All @@ -845,11 +852,13 @@ PHP_LIBXML_API void php_libxml_ctx_warning(void *ctx, const char *msg, ...)
va_end(args);
}

#if LIBXML_VERSION >= 21200
static void php_libxml_structured_error_handler(void *userData, const xmlError *error)
#else
static void php_libxml_structured_error_handler(void *userData, xmlErrorPtr error)
#endif
{
_php_list_set_error_structure(error, NULL, 0, 0);

return;
}

PHP_LIBXML_API void php_libxml_error_handler(void *ctx, const char *msg, ...)
Expand Down Expand Up @@ -1077,11 +1086,9 @@ PHP_FUNCTION(libxml_use_internal_errors)
/* {{{ Retrieve last error from libxml */
PHP_FUNCTION(libxml_get_last_error)
{
xmlErrorPtr error;

ZEND_PARSE_PARAMETERS_NONE();

error = xmlGetLastError();
const xmlError* error = xmlGetLastError();

if (error) {
object_init_ex(return_value, libxmlerror_class_entry);
Expand All @@ -1108,7 +1115,6 @@ PHP_FUNCTION(libxml_get_last_error)
/* {{{ Retrieve array of errors */
PHP_FUNCTION(libxml_get_errors)
{

xmlErrorPtr error;

ZEND_PARSE_PARAMETERS_NONE();
Expand Down
12 changes: 8 additions & 4 deletions ext/libxml/php_libxml.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,27 @@ ZEND_TSRMLS_CACHE_EXTERN()
* See libxml2 globals.c and parserInternals.c.
* The unique_name argument allows multiple sanitizes and restores within the
* same function, even nested is necessary. */
#define PHP_LIBXML_SANITIZE_GLOBALS(unique_name) \
# define PHP_LIBXML_SANITIZE_GLOBALS(unique_name) \
ZEND_DIAGNOSTIC_IGNORED_START("-Wdeprecated-declarations") \
int xml_old_loadsubset_##unique_name = xmlLoadExtDtdDefaultValue; \
xmlLoadExtDtdDefaultValue = 0; \
int xml_old_validate_##unique_name = xmlDoValidityCheckingDefaultValue; \
xmlDoValidityCheckingDefaultValue = 0; \
int xml_old_pedantic_##unique_name = xmlPedanticParserDefault(0); \
int xml_old_substitute_##unique_name = xmlSubstituteEntitiesDefault(0); \
int xml_old_linenrs_##unique_name = xmlLineNumbersDefault(0); \
int xml_old_blanks_##unique_name = xmlKeepBlanksDefault(1);
int xml_old_blanks_##unique_name = xmlKeepBlanksDefault(1); \
ZEND_DIAGNOSTIC_IGNORED_END

#define PHP_LIBXML_RESTORE_GLOBALS(unique_name) \
# define PHP_LIBXML_RESTORE_GLOBALS(unique_name) \
ZEND_DIAGNOSTIC_IGNORED_START("-Wdeprecated-declarations") \
xmlLoadExtDtdDefaultValue = xml_old_loadsubset_##unique_name; \
xmlDoValidityCheckingDefaultValue = xml_old_validate_##unique_name; \
(void) xmlPedanticParserDefault(xml_old_pedantic_##unique_name); \
(void) xmlSubstituteEntitiesDefault(xml_old_substitute_##unique_name); \
(void) xmlLineNumbersDefault(xml_old_linenrs_##unique_name); \
(void) xmlKeepBlanksDefault(xml_old_blanks_##unique_name);
(void) xmlKeepBlanksDefault(xml_old_blanks_##unique_name); \
ZEND_DIAGNOSTIC_IGNORED_END

/* Alternative for above, working directly on the context and not setting globals.
* Generally faster because no locking is involved, and this has the advantage that it sets the options to a known good value. */
Expand Down
4 changes: 2 additions & 2 deletions ext/xml/tests/bug81351.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ $code = xml_get_error_code($parser);
$error = xml_error_string($code);
echo "xml_parse returned $success, xml_get_error_code = $code, xml_error_string = $error\r\n";
?>
--EXPECT--
--EXPECTF--
xml_parse returned 1, xml_get_error_code = 0, xml_error_string = No error
xml_parse returned 0, xml_get_error_code = 5, xml_error_string = Invalid document end
%rxml_parse returned 0, xml_get_error_code = 5, xml_error_string = Invalid document end|xml_parse returned 0, xml_get_error_code = 77, xml_error_string = Tag not finished%r
6 changes: 3 additions & 3 deletions ext/xml/tests/xml_error_string_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ foreach ($xmls as $xml) {
xml_parser_free($xml_parser);
}
?>
--EXPECT--
int(5)
string(20) "Invalid document end"
--EXPECTF--
int(%r5|77%r)
string(%d) %r"Invalid document end"|"Tag not finished"%r
int(47)
string(35) "Processing Instruction not finished"
int(57)
Expand Down