Skip to content
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
6 changes: 4 additions & 2 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -1287,11 +1287,13 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t so
if (keep_blanks == 0 && ! (options & XML_PARSE_NOBLANKS)) {
options |= XML_PARSE_NOBLANKS;
}
if (recover) {
options |= XML_PARSE_RECOVER;
}

php_libxml_sanitize_parse_ctxt_options(ctxt);
xmlCtxtUseOptions(ctxt, options);

ctxt->recovery = recover;
if (recover) {
old_error_reporting = EG(error_reporting);
EG(error_reporting) = old_error_reporting | E_WARNING;
Expand All @@ -1301,7 +1303,7 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t so

if (ctxt->wellFormed || recover) {
ret = ctxt->myDoc;
if (ctxt->recovery) {
if (recover) {
EG(error_reporting) = old_error_reporting;
}
/* If loading from memory, set the base reference uri for the document */
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/tests/DOMDocument_loadHTMLfile_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ $result = $doc->loadHTMLFile(__DIR__ . "/ffff/test.html");
assert($result === false);
?>
--EXPECTF--
%r(PHP ){0,1}%rWarning: DOMDocument::loadHTMLFile(): I/O warning : failed to load external entity %s
%r(PHP ){0,1}%rWarning: DOMDocument::loadHTMLFile(): I/O %s
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 <[email protected]>
--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 <[email protected]>
--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(): %s

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 <[email protected]>
--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 && <= 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_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 <[email protected]>
--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(): %s

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
2 changes: 1 addition & 1 deletion ext/dom/tests/DOMDocument_relaxNGValidate_error2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $result = $doc->relaxNGValidate($rng);
var_dump($result);
?>
--EXPECTF--
Warning: DOMDocument::relaxNGValidate(): I/O warning : failed to load external entity "%s/foo.rng" in %s on line %d
Warning: DOMDocument::relaxNGValidate(): I/O %s : failed to load %s

Warning: DOMDocument::relaxNGValidate(): xmlRelaxNGParse: could not load %s/foo.rng in %s on line %d

Expand Down
4 changes: 4 additions & 0 deletions ext/dom/tests/DOMDocument_saveHTMLFile_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Knut Urdalen <[email protected]>
#PHPTestFest2009 Norway 2009-06-09 \o/
--EXTENSIONS--
dom
--SKIPIF--
<?php
if (LIBXML_VERSION >= 21300) die("skip see https://gitlab.gnome.org/GNOME/libxml2/-/issues/756");
?>
--FILE--
<?php
$filename = __DIR__."/DOMDocument_saveHTMLFile_basic.html";
Expand Down
4 changes: 4 additions & 0 deletions ext/dom/tests/DOMDocument_saveHTMLFile_formatOutput.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Knut Urdalen <[email protected]>
#PHPTestFest2009 Norway 2009-06-09 \o/
--EXTENSIONS--
dom
--SKIPIF--
<?php
if (LIBXML_VERSION >= 21300) die("skip see https://gitlab.gnome.org/GNOME/libxml2/-/issues/756");
?>
--FILE--
<?php
$filename = __DIR__."/DOMDocument_saveHTMLFile_formatOutput.html";
Expand Down
32 changes: 32 additions & 0 deletions ext/dom/tests/DOMDocument_saveHTMLFile_formatOutput_gte_2_13.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
DOMDocument::saveHTMLFile() should format output on demand
--CREDITS--
Knut Urdalen <[email protected]>
#PHPTestFest2009 Norway 2009-06-09 \o/
--EXTENSIONS--
dom
--SKIPIF--
<?php
if (LIBXML_VERSION < 21300) die("skip see https://gitlab.gnome.org/GNOME/libxml2/-/issues/756");
?>
--FILE--
<?php
$filename = __DIR__."/DOMDocument_saveHTMLFile_formatOutput_gte_2_13.html";
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$root = $doc->createElement('html');
$root = $doc->appendChild($root);
$head = $doc->createElement('head');
$head = $root->appendChild($head);
$title = $doc->createElement('title');
$title = $head->appendChild($title);
$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);
$bytes = $doc->saveHTMLFile($filename);
var_dump($bytes);
echo file_get_contents($filename);
unlink($filename);
?>
--EXPECT--
int(59)
<html><head><title>This is the title</title></head></html>
31 changes: 31 additions & 0 deletions ext/dom/tests/DOMDocument_saveHTML_basic_gte_2_13.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
DOMDocument::saveHTMLFile() should dump the internal document into a file using HTML formatting
--CREDITS--
Knut Urdalen <[email protected]>
#PHPTestFest2009 Norway 2009-06-09 \o/
--EXTENSIONS--
dom
--SKIPIF--
<?php
if (LIBXML_VERSION < 21300) die("skip see https://gitlab.gnome.org/GNOME/libxml2/-/issues/756");
?>
--FILE--
<?php
$filename = __DIR__."/DOMDocument_saveHTMLFile_basic_gte_2_13.html";
$doc = new DOMDocument('1.0');
$root = $doc->createElement('html');
$root = $doc->appendChild($root);
$head = $doc->createElement('head');
$head = $root->appendChild($head);
$title = $doc->createElement('title');
$title = $head->appendChild($title);
$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);
$bytes = $doc->saveHTMLFile($filename);
var_dump($bytes);
echo file_get_contents($filename);
unlink($filename);
?>
--EXPECT--
int(59)
<html><head><title>This is the title</title></head></html>
2 changes: 1 addition & 1 deletion ext/dom/tests/DOMDocument_schemaValidate_error5.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var_dump($result);

?>
--EXPECTF--
Warning: DOMDocument::schemaValidate(): I/O warning : failed to load external entity "%snon-existent-file" in %s.php on line %d
Warning: DOMDocument::schemaValidate(): I/O %s : failed to load %s

Warning: DOMDocument::schemaValidate(): Failed to locate the main schema resource at '%s/non-existent-file'. in %s.php on line %d

Expand Down
14 changes: 4 additions & 10 deletions ext/dom/tests/dom_create_element.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,10 @@ try {
print $e->getMessage() . "\n";
}

/* This isn't because the xml namespace isn't there and we can't create it */
print "29 DOMElement::__construct('xml:valid', '', 'http://www.w3.org/XML/1998/namespace')\n";
try {
$element = new DomElement('xml:valid', '', 'http://www.w3.org/XML/1998/namespace');
print "valid\n";
} catch (Exception $e) {
print $e->getMessage() . "\n";
}
/* There used to be a 29 here that tested DOMElement::__construct('xml:valid', '', 'http://www.w3.org/XML/1998/namespace').
* In libxml2 version 2.12 or prior this didn't work because the xml namespace isn't there and you can't create it without
* a document. Starting from libxml2 version 2.13 it does actually work because the XML namespace is statically defined.
* The behaviour from version 2.13 is actually the desired behaviour anyway. */


/* the qualifiedName or its prefix is "xmlns" and the namespaceURI is
Expand Down Expand Up @@ -378,8 +374,6 @@ Namespace Error
Namespace Error
28 DOMDocument::createElementNS('http://www.w3.org/XML/1998/namespace', 'xml:valid')
valid
29 DOMElement::__construct('xml:valid', '', 'http://www.w3.org/XML/1998/namespace')
Namespace Error
30 DOMDocument::createElementNS('http://wrong.namespaceURI.com', 'xmlns:valid')
Namespace Error
31 DOMElement::__construct('xmlns:valid', '', 'http://wrong.namespaceURI.com')
Expand Down
18 changes: 13 additions & 5 deletions ext/libxml/libxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,10 @@ php_libxml_input_buffer_create_filename(const char *URI, xmlCharEncoding enc)
static xmlOutputBufferPtr
php_libxml_output_buffer_create_filename(const char *URI,
xmlCharEncodingHandlerPtr encoder,
int compression ATTRIBUTE_UNUSED)
int compression)
{
ZEND_IGNORE_VALUE(compression);

xmlOutputBufferPtr ret;
xmlURIPtr puri;
void *context = NULL;
Expand Down Expand Up @@ -483,7 +485,11 @@ static void _php_libxml_free_error(void *ptr)
xmlResetError((xmlErrorPtr) ptr);
}

static void _php_list_set_error_structure(xmlErrorPtr error, const char *msg)
#if LIBXML_VERSION >= 21200
static void _php_list_set_error_structure(const xmlError *error, const char *msg)
#else
static void _php_list_set_error_structure(xmlError *error, const char *msg)
#endif
{
xmlError error_copy;
int ret;
Expand Down Expand Up @@ -736,7 +742,11 @@ PHP_LIBXML_API void php_libxml_ctx_warning(void *ctx, const char *msg, ...)
va_end(args);
}

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

Expand Down Expand Up @@ -1009,11 +1019,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 Down
Loading
Loading