Skip to content

Commit 7ac17ae

Browse files
Remove "<!DOCTYPE ...>" line from generated Cobertura XML
The DOCTYPE declaration referenced a remote DTD URL. This is problematic because XML parsers may attempt to fetch the DTD over the network, causing timeouts or failures when the remote server is unavailable. No common consumer of Cobertura XML (GitLab CI, Jenkins, Codecov, etc.) performs DTD validation; they only parse elements and attributes. Furthermore, the referenced URL is no longer valid.
1 parent 24f1d73 commit 7ac17ae

File tree

7 files changed

+9
-17
lines changed

7 files changed

+9
-17
lines changed

ChangeLog-14.0.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
44

5+
## [14.0.1] - 2026-MM-DD
6+
7+
### Changed
8+
9+
* The XML document of the code coverage report in Cobertura XML format no longer has the `<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">` line at the beginning. No document exists at this URL any more, referencing remote DTD URLs is problematic, and no common consumer of Cobertura XML relies on this line.
10+
511
## [14.0.0] - 2026-04-03
612

713
### Added
@@ -28,4 +34,5 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
2834

2935
* The `SebastianBergmann\CodeCoverage\Report\PHP` class was removed, use the new `SebastianBergmann\CodeCoverage\Serializer` class instead
3036

37+
[14.0.1]: https://github.com/sebastianbergmann/php-code-coverage/compare/14.0.0...main
3138
[14.0.0]: https://github.com/sebastianbergmann/php-code-coverage/compare/13.0.2...14.0.0

src/Report/Cobertura.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use function range;
1717
use function str_replace;
1818
use function time;
19-
use DOMImplementation;
19+
use DOMDocument;
2020
use SebastianBergmann\CodeCoverage\Node\Directory;
2121
use SebastianBergmann\CodeCoverage\Node\File;
2222
use SebastianBergmann\CodeCoverage\Util\Filesystem;
@@ -39,17 +39,7 @@ public function process(Directory $report, ?string $target = null): string
3939
{
4040
$time = (string) time();
4141

42-
$implementation = new DOMImplementation;
43-
44-
$documentType = $implementation->createDocumentType(
45-
'coverage',
46-
'',
47-
'http://cobertura.sourceforge.net/xml/coverage-04.dtd',
48-
);
49-
50-
$document = $implementation->createDocument('', '', $documentType);
51-
$document->xmlVersion = '1.0';
52-
$document->encoding = 'UTF-8';
42+
$document = new DOMDocument('1.0', 'UTF-8');
5343

5444
$coverageElement = $document->createElement('coverage');
5545

tests/_files/Report/Cobertura/BankAccount-line.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
32
<coverage line-rate="0.625" branch-rate="0" lines-covered="5" lines-valid="8" branches-covered="0" branches-valid="0" complexity="5" version="0.4" timestamp="%i">
43
<sources>
54
<source>%s</source>

tests/_files/Report/Cobertura/BankAccount-path.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
32
<coverage line-rate="0.625" branch-rate="0.42857142857143" lines-covered="5" lines-valid="8" branches-covered="3" branches-valid="7" complexity="5" version="0.4" timestamp="%i">
43
<sources>
54
<source>%s</source>

tests/_files/Report/Cobertura/class-with-anonymous-function.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
32
<coverage line-rate="1" branch-rate="0" lines-covered="8" lines-valid="8" branches-covered="0" branches-valid="0" complexity="1" version="0.4" timestamp="%i">
43
<sources>
54
<source>%s</source>

tests/_files/Report/Cobertura/class-with-outside-function.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
32
<coverage line-rate="0.75" branch-rate="0" lines-covered="3" lines-valid="4" branches-covered="0" branches-valid="0" complexity="3" version="0.4" timestamp="%i">
43
<sources>
54
<source>%s</source>

tests/_files/Report/Cobertura/ignored-lines.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
32
<coverage line-rate="1" branch-rate="0" lines-covered="1" lines-valid="1" branches-covered="0" branches-valid="0" complexity="2" version="0.4" timestamp="%i">
43
<sources>
54
<source>%s</source>

0 commit comments

Comments
 (0)