Skip to content

Commit 4fe8213

Browse files
authored
Backport libxml2 2.13.2 fixes (#14816)
Backproted from #14789
1 parent 7b74cad commit 4fe8213

19 files changed

+109
-27
lines changed

ext/dom/document.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,11 +1292,13 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t so
12921292
if (keep_blanks == 0 && ! (options & XML_PARSE_NOBLANKS)) {
12931293
options |= XML_PARSE_NOBLANKS;
12941294
}
1295+
if (recover) {
1296+
options |= XML_PARSE_RECOVER;
1297+
}
12951298

12961299
php_libxml_sanitize_parse_ctxt_options(ctxt);
12971300
xmlCtxtUseOptions(ctxt, options);
12981301

1299-
ctxt->recovery = recover;
13001302
if (recover) {
13011303
old_error_reporting = EG(error_reporting);
13021304
EG(error_reporting) = old_error_reporting | E_WARNING;
@@ -1306,7 +1308,7 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t so
13061308

13071309
if (ctxt->wellFormed || recover) {
13081310
ret = ctxt->myDoc;
1309-
if (ctxt->recovery) {
1311+
if (recover) {
13101312
EG(error_reporting) = old_error_reporting;
13111313
}
13121314
/* If loading from memory, set the base reference uri for the document */

ext/dom/tests/DOMDocument_loadHTMLfile_error1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ $result = $doc->loadHTMLFile(__DIR__ . "/ffff/test.html");
1515
assert($result === false);
1616
?>
1717
--EXPECTF--
18-
%r(PHP ){0,1}%rWarning: DOMDocument::loadHTMLFile(): I/O warning : failed to load external entity %s
18+
%r(PHP ){0,1}%rWarning: DOMDocument::loadHTMLFile(): I/O %s

ext/dom/tests/DOMDocument_loadXML_error2_gte2_12.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ domdocumentloadxml_test_method.inc
2323
--EXPECTF--
2424
Warning: DOMDocument::loadXML(): AttValue: " or ' expected in Entity, line: 4 in %s on line %d
2525

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

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

ext/dom/tests/DOMDocument_load_error2_gte2_12.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ domdocumentload_test_method.inc
2323
--EXPECTF--
2424
Warning: DOMDocument::load(): AttValue: " or ' expected in %s on line %d
2525

26-
Warning: DOMDocument::load(): internal error: xmlParseStartTag: problem parsing attributes in %s on line %d
26+
Warning: DOMDocument::load():%sattributes%s
2727

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

ext/dom/tests/DOMDocument_relaxNGValidate_error2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $result = $doc->relaxNGValidate($rng);
2020
var_dump($result);
2121
?>
2222
--EXPECTF--
23-
Warning: DOMDocument::relaxNGValidate(): I/O warning : failed to load external entity "%s/foo.rng" in %s on line %d
23+
Warning: DOMDocument::relaxNGValidate(): I/O %s : failed to load %s
2424

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

ext/dom/tests/DOMDocument_saveHTMLFile_basic.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ Knut Urdalen <knut@php.net>
55
#PHPTestFest2009 Norway 2009-06-09 \o/
66
--EXTENSIONS--
77
dom
8+
--SKIPIF--
9+
<?php
10+
if (LIBXML_VERSION >= 21300) die("skip see https://gitlab.gnome.org/GNOME/libxml2/-/issues/756");
11+
?>
812
--FILE--
913
<?php
1014
$filename = __DIR__."/DOMDocument_saveHTMLFile_basic.html";

ext/dom/tests/DOMDocument_saveHTMLFile_formatOutput.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ Knut Urdalen <knut@php.net>
55
#PHPTestFest2009 Norway 2009-06-09 \o/
66
--EXTENSIONS--
77
dom
8+
--SKIPIF--
9+
<?php
10+
if (LIBXML_VERSION >= 21300) die("skip see https://gitlab.gnome.org/GNOME/libxml2/-/issues/756");
11+
?>
812
--FILE--
913
<?php
1014
$filename = __DIR__."/DOMDocument_saveHTMLFile_formatOutput.html";
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
DOMDocument::saveHTMLFile() should format output on demand
3+
--CREDITS--
4+
Knut Urdalen <knut@php.net>
5+
#PHPTestFest2009 Norway 2009-06-09 \o/
6+
--EXTENSIONS--
7+
dom
8+
--SKIPIF--
9+
<?php
10+
if (LIBXML_VERSION < 21300) die("skip see https://gitlab.gnome.org/GNOME/libxml2/-/issues/756");
11+
?>
12+
--FILE--
13+
<?php
14+
$filename = __DIR__."/DOMDocument_saveHTMLFile_formatOutput_gte_2_13.html";
15+
$doc = new DOMDocument('1.0');
16+
$doc->formatOutput = true;
17+
$root = $doc->createElement('html');
18+
$root = $doc->appendChild($root);
19+
$head = $doc->createElement('head');
20+
$head = $root->appendChild($head);
21+
$title = $doc->createElement('title');
22+
$title = $head->appendChild($title);
23+
$text = $doc->createTextNode('This is the title');
24+
$text = $title->appendChild($text);
25+
$bytes = $doc->saveHTMLFile($filename);
26+
var_dump($bytes);
27+
echo file_get_contents($filename);
28+
unlink($filename);
29+
?>
30+
--EXPECT--
31+
int(59)
32+
<html><head><title>This is the title</title></head></html>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
DOMDocument::saveHTMLFile() should dump the internal document into a file using HTML formatting
3+
--CREDITS--
4+
Knut Urdalen <knut@php.net>
5+
#PHPTestFest2009 Norway 2009-06-09 \o/
6+
--EXTENSIONS--
7+
dom
8+
--SKIPIF--
9+
<?php
10+
if (LIBXML_VERSION < 21300) die("skip see https://gitlab.gnome.org/GNOME/libxml2/-/issues/756");
11+
?>
12+
--FILE--
13+
<?php
14+
$filename = __DIR__."/DOMDocument_saveHTMLFile_basic_gte_2_13.html";
15+
$doc = new DOMDocument('1.0');
16+
$root = $doc->createElement('html');
17+
$root = $doc->appendChild($root);
18+
$head = $doc->createElement('head');
19+
$head = $root->appendChild($head);
20+
$title = $doc->createElement('title');
21+
$title = $head->appendChild($title);
22+
$text = $doc->createTextNode('This is the title');
23+
$text = $title->appendChild($text);
24+
$bytes = $doc->saveHTMLFile($filename);
25+
var_dump($bytes);
26+
echo file_get_contents($filename);
27+
unlink($filename);
28+
?>
29+
--EXPECT--
30+
int(59)
31+
<html><head><title>This is the title</title></head></html>

ext/dom/tests/DOMDocument_schemaValidate_error5.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var_dump($result);
1717

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

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

0 commit comments

Comments
 (0)