Skip to content

Commit 8b651d7

Browse files
authored
Merge pull request #113 from bramley/no_encoding_unit_test
Set the DOM encoding to UTF-8 when it is not specified in a feed's xml declaration
2 parents 76f537d + e045c14 commit 8b651d7

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/Reader/Reader.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ public static function importString($string)
363363
$disableEntityLoaderFlag = self::disableEntityLoader();
364364
$dom = new DOMDocument();
365365
$status = $dom->loadXML(trim($string));
366+
if ($dom->encoding === null) {
367+
$dom->encoding = 'UTF-8';
368+
}
366369
foreach ($dom->childNodes as $child) {
367370
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
368371
throw new Exception\InvalidArgumentException(

test/Reader/Entry/AtomStandaloneEntryTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,20 @@ public function testGetsContentFromAtom10XhtmlNamespaced(): void
249249
$this->assertEquals('<p class="x:"><em>Entry Content &amp;x:</em></p>', $entry->getContent());
250250
}
251251

252+
/**
253+
* XHTML document does not have encoding
254+
*
255+
* @group LaminasRATOMCONTENT
256+
*/
257+
public function testGetsContentFromAtom10XhtmlNamespacedNoEncoding(): void
258+
{
259+
$entry = Reader\Reader::importString(
260+
file_get_contents($this->feedSamplePath . '/content/atom10_XhtmlNoEncoding.xml')
261+
);
262+
$this->assertInstanceOf(Atom::class, $entry);
263+
$this->assertEquals('<p class="x:"><em>Entry Content &amp;x:</em></p>', $entry->getContent());
264+
}
265+
252266
/**
253267
* Get Link (Unencoded Text)
254268
*
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" ?>
2+
<entry xmlns="http://www.w3.org/2005/Atom">
3+
<content type="xhtml" xmlns:x="http://www.w3.org/1999/xhtml">
4+
<x:div>
5+
<x:p class="x:"><x:em>Entry Content &amp;x:</x:em></x:p>
6+
</x:div>
7+
</content>
8+
</entry>

0 commit comments

Comments
 (0)