Skip to content

Commit 3c7f40e

Browse files
committed
support &amp; in <item/>
1 parent 5225c05 commit 3c7f40e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Source/Suin/RSSWriter/SimpleXMLElement.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,13 @@
44

55
class SimpleXMLElement extends \SimpleXMLElement
66
{
7+
public function addChild($name, $value = null, $namespace = null)
8+
{
9+
if ( $value !== null and is_string($value) === true )
10+
{
11+
$value = str_replace('&', '&amp;', $value);
12+
}
13+
14+
return parent::addChild($name, $value, $namespace);
15+
}
716
}

Tests/Suin/RSSWriter/ItemTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,18 @@ public function testAsXML_test_Japanese()
155155

156156
$this->assertXmlStringEqualsXmlString($expect, $item->asXML()->asXML());
157157
}
158+
159+
public function test_with_amp()
160+
{
161+
$item = new Item();
162+
$item
163+
->title('test&test')
164+
->url('url&url')
165+
->description('desc&desc');
166+
$expect = '<?xml version="1.0" encoding="UTF-8"?>
167+
<item><title>test&amp;test</title><link>url&amp;url</link><description>desc&amp;desc</description></item>
168+
';
169+
170+
$this->assertSame($expect, $item->asXML()->asXML());
171+
}
158172
}

0 commit comments

Comments
 (0)