Skip to content

Commit 8a2195d

Browse files
nielsdosremicollet
authored andcommitted
Fix GH-11160: Few tests failed building with new libxml 2.11.0
It's possible to categorise the failures into 2 categories: - Changed error message. In this case we either duplicate the test and modify the error message. Or if the change in error message is small, we use the EXPECTF matchers to make the test compatible with both old and new versions of libxml2. - Missing warnings. This is caused by a change in libxml2 where the parser started using SAX APIs internally [1]. In this case the error_type passed to php_libxml_internal_error_handler() changed from PHP_LIBXML_ERROR to PHP_LIBXML_CTX_WARNING because it internally started to use the SAX handlers instead of the generic handlers. However, for the SAX handlers the current input stack is empty, so nothing is actually printed. I fixed this by falling back to a regular warning without a filename & line number reference, which mimicks the old behaviour. Furthermore, this change now also shows an additional warning in a test which was previously hidden. [1] https://gitlab.gnome.org/GNOME/libxml2/-/commit/9a82b94a94bd310db426edd453b0f38c6c8f69f5 Closes GH-11162. (cherry picked from commit 7c0dfc5cf58d3c445b935fa14ea8f5f13568c419) (cherry picked from commit 78ae088)
1 parent 134f821 commit 8a2195d

25 files changed

+408
-68
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Test DOMDocument::loadXML() detects not-well formed XML
3+
--SKIPIF--
4+
<?php
5+
if (LIBXML_VERSION < 21100) die('skip libxml2 test variant for version >= 2.11');
6+
?>
7+
--DESCRIPTION--
8+
This test verifies the method detects attributes values not closed between " or '
9+
Environment variables used in the test:
10+
- XML_FILE: the xml file to load
11+
- LOAD_OPTIONS: the second parameter to pass to the method
12+
- EXPECTED_RESULT: the expected result
13+
--CREDITS--
14+
Antonio Diaz Ruiz <[email protected]>
15+
--INI--
16+
assert.bail=true
17+
--EXTENSIONS--
18+
dom
19+
--ENV--
20+
XML_FILE=/not_well_formed2.xml
21+
LOAD_OPTIONS=0
22+
EXPECTED_RESULT=0
23+
--FILE_EXTERNAL--
24+
domdocumentloadxml_test_method.inc
25+
--EXPECTF--
26+
Warning: DOMDocument::loadXML(): AttValue: " or ' expected in Entity, line: 4 in %s on line %d
27+
28+
Warning: DOMDocument::loadXML(): internal error: xmlParseStartTag: problem parsing attributes in Entity, line: 4 in %s on line %d
29+
30+
Warning: DOMDocument::loadXML(): Couldn't find end of Start Tag book line 4 in Entity, line: 4 in %s on line %d
31+
32+
Warning: DOMDocument::loadXML(): Opening and ending tag mismatch: books line 3 and book in Entity, line: 7 in %s on line %d
33+
34+
Warning: DOMDocument::loadXML(): Extra content at the end of the document in Entity, line: 8 in %s on line %d

ext/dom/tests/DOMDocument_loadXML_error2.phpt renamed to ext/dom/tests/DOMDocument_loadXML_error2_pre2_11.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
--TEST--
22
Test DOMDocument::loadXML() detects not-well formed XML
3+
--SKIPIF--
4+
<?php
5+
include('skipif.inc');
6+
if (LIBXML_VERSION >= 21100) die('skip libxml2 test variant for version < 2.11');
7+
?>
38
--DESCRIPTION--
49
This test verifies the method detects attributes values not closed between " or '
510
Environment variables used in the test:
@@ -10,8 +15,6 @@ Environment variables used in the test:
1015
Antonio Diaz Ruiz <[email protected]>
1116
--INI--
1217
assert.bail=true
13-
--SKIPIF--
14-
<?php include('skipif.inc'); ?>
1518
--ENV--
1619
XML_FILE=/not_well_formed2.xml
1720
LOAD_OPTIONS=0
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Test DOMDocument::load() detects not-well formed
3+
--SKIPIF--
4+
<?php
5+
if (LIBXML_VERSION < 21100) die('skip libxml2 test variant for version >= 2.11');
6+
?>
7+
--DESCRIPTION--
8+
This test verifies the method detects attributes values not closed between " or '
9+
Environment variables used in the test:
10+
- XML_FILE: the xml file to load
11+
- LOAD_OPTIONS: the second parameter to pass to the method
12+
- EXPECTED_RESULT: the expected result
13+
--CREDITS--
14+
Antonio Diaz Ruiz <[email protected]>
15+
--INI--
16+
assert.bail=true
17+
--EXTENSIONS--
18+
dom
19+
--ENV--
20+
XML_FILE=/not_well_formed2.xml
21+
LOAD_OPTIONS=0
22+
EXPECTED_RESULT=0
23+
--FILE_EXTERNAL--
24+
domdocumentload_test_method.inc
25+
--EXPECTF--
26+
Warning: DOMDocument::load(): AttValue: " or ' expected in %s on line %d
27+
28+
Warning: DOMDocument::load(): internal error: xmlParseStartTag: problem parsing attributes in %s on line %d
29+
30+
Warning: DOMDocument::load(): Couldn't find end of Start Tag book line 4 in %s on line %d
31+
32+
Warning: DOMDocument::load(): Opening and ending tag mismatch: books line 3 and book in %s on line %d
33+
34+
Warning: DOMDocument::load(): Extra content at the end of the document in %s on line %d

ext/dom/tests/DOMDocument_load_error2.phpt renamed to ext/dom/tests/DOMDocument_load_error2_pre2_11.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
--TEST--
22
Test DOMDocument::load() detects not-well formed XML
3+
--SKIPIF--
4+
<?php
5+
include('skipif.inc');
6+
if (LIBXML_VERSION >= 21100) die('skip libxml2 test variant for version < 2.11');
7+
?>
38
--DESCRIPTION--
49
This test verifies the method detects attributes values not closed between " or '
510
Environment variables used in the test:
@@ -10,8 +15,6 @@ Environment variables used in the test:
1015
Antonio Diaz Ruiz <[email protected]>
1116
--INI--
1217
assert.bail=true
13-
--SKIPIF--
14-
<?php include('skipif.inc'); ?>
1518
--ENV--
1619
XML_FILE=/not_well_formed2.xml
1720
LOAD_OPTIONS=0

ext/libxml/libxml.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,8 @@ static void php_libxml_ctx_error_level(int level, void *ctx, const char *msg)
574574
} else {
575575
php_error_docref(NULL, level, "%s in Entity, line: %d", msg, parser->input->line);
576576
}
577+
} else {
578+
php_error_docref(NULL, E_WARNING, "%s", msg);
577579
}
578580
}
579581

ext/libxml/tests/bug61367-read_2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ bool(true)
5555
int(4)
5656
bool(true)
5757

58-
Warning: DOMDocument::loadXML(): I/O warning : failed to load external entity "file:///%s/test_bug_61367-read/bad" in %s on line %d
58+
Warning: DOMDocument::loadXML(): %Sfailed to load external entity "file:///%s/test_bug_61367-read/bad" in %s on line %d
5959

6060
Notice: Trying to get property 'nodeValue' of non-object in %s on line %d

ext/libxml/tests/libxml_disable_entity_loader_2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ echo "Done\n";
3636
bool(true)
3737
bool(false)
3838

39-
Warning: DOMDocument::loadXML(): I/O warning : failed to load external entity "%s" in %s on line %d
39+
Warning: DOMDocument::loadXML(): %Sfailed to load external entity "%s" in %s on line %d
4040
bool(true)
4141
Done

ext/libxml/tests/libxml_set_external_entity_loader_error1.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Warning: libxml_set_external_entity_loader() expects exactly 1 parameter, 2 give
3535
NULL
3636
bool(true)
3737

38+
Warning: DOMDocument::validate(): Call to user entity loader callback %s
39+
3840
Warning: DOMDocument::validate(): Could not load the external subset "http://example.com/foobar" in %s on line %d
3941
Exception: Too few arguments to function {closure}(), 3 passed and exactly 4 expected
4042
Done.

ext/libxml/tests/libxml_set_external_entity_loader_variation2.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ echo "Done.\n";
3838
string(10) "-//FOO/BAR"
3939
string(%d) "%sfoobar.dtd"
4040

41+
Warning: DOMDocument::validate(): Failed to load external entity "-//FOO/BAR" in %s on line %d
42+
4143
Warning: DOMDocument::validate(): Could not load the external subset "foobar.dtd" in %s on line %d
4244
bool(false)
4345
bool(true)

ext/openssl/tests/ServerClientTestCase.inc

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,14 @@ const WORKER_ARGV_VALUE = 'RUN_WORKER';
44

55
const WORKER_DEFAULT_NAME = 'server';
66

7-
function phpt_notify(string $worker = WORKER_DEFAULT_NAME, string $message = ""): void
7+
function phpt_notify($worker = WORKER_DEFAULT_NAME)
88
{
9-
ServerClientTestCase::getInstance()->notify($worker, $message);
9+
ServerClientTestCase::getInstance()->notify($worker);
1010
}
1111

12-
function phpt_wait($worker = WORKER_DEFAULT_NAME, $timeout = null): ?string
12+
function phpt_wait($worker = WORKER_DEFAULT_NAME, $timeout = null)
1313
{
14-
return ServerClientTestCase::getInstance()->wait($worker, $timeout);
15-
}
16-
17-
function phpt_notify_server_start($server): void
18-
{
19-
ServerClientTestCase::getInstance()->notify_server_start($server);
14+
ServerClientTestCase::getInstance()->wait($worker, $timeout);
2015
}
2116

2217
function phpt_has_sslv3() {
@@ -124,73 +119,43 @@ class ServerClientTestCase
124119
eval($code);
125120
}
126121

127-
/**
128-
* Run client and all workers
129-
*
130-
* @param string $clientCode The client PHP code
131-
* @param string|array $workerCode
132-
* @param bool $ephemeral Select whether automatic port selection and automatic awaiting is used
133-
* @return void
134-
* @throws Exception
135-
*/
136-
public function run(string $clientCode, $workerCode, bool $ephemeral = true): void
122+
public function run($masterCode, $workerCode)
137123
{
138124
if (!is_array($workerCode)) {
139125
$workerCode = [WORKER_DEFAULT_NAME => $workerCode];
140126
}
141-
reset($workerCode);
142-
$code = current($workerCode);
143-
$worker = key($workerCode);
144-
while ($worker != null) {
127+
foreach ($workerCode as $worker => $code) {
145128
$this->spawnWorkerProcess($worker, $this->stripPhpTagsFromCode($code));
146-
$code = next($workerCode);
147-
if ($ephemeral) {
148-
$addr = trim($this->wait($worker));
149-
if (empty($addr)) {
150-
throw new \Exception("Failed server start");
151-
}
152-
if ($code === false) {
153-
$clientCode = preg_replace('/{{\s*ADDR\s*}}/', $addr, $clientCode);
154-
} else {
155-
$code = preg_replace('/{{\s*ADDR\s*}}/', $addr, $code);
156-
}
157-
}
158-
$worker = key($workerCode);
159129
}
160-
161-
eval($this->stripPhpTagsFromCode($clientCode));
130+
eval($this->stripPhpTagsFromCode($masterCode));
162131
foreach ($workerCode as $worker => $code) {
163132
$this->cleanupWorkerProcess($worker);
164133
}
165134
}
166135

167-
public function wait($worker, $timeout = null): ?string
136+
public function wait($worker, $timeout = null)
168137
{
169138
$handle = $this->isWorker ? STDIN : $this->workerStdOut[$worker];
170139
if ($timeout === null) {
171-
return fgets($handle);
140+
fgets($handle);
141+
return true;
172142
}
173143

174144
stream_set_blocking($handle, false);
175145
$read = [$handle];
176146
$result = stream_select($read, $write, $except, $timeout);
177147
if (!$result) {
178-
return null;
148+
return false;
179149
}
180150

181-
$result = fgets($handle);
151+
fgets($handle);
182152
stream_set_blocking($handle, true);
183-
return $result;
184-
}
185-
186-
public function notify(string $worker, string $message = ""): void
187-
{
188-
fwrite($this->isWorker ? STDOUT : $this->workerStdIn[$worker], "$message\n");
153+
return true;
189154
}
190155

191-
public function notify_server_start($server): void
156+
public function notify($worker)
192157
{
193-
echo stream_socket_get_name($server, false) . "\n";
158+
fwrite($this->isWorker ? STDOUT : $this->workerStdIn[$worker], "\n");
194159
}
195160
}
196161

0 commit comments

Comments
 (0)