Skip to content

Commit dd4af2c

Browse files
committed
Handle self-closing xml elements in XmlFragment.
Fixes #41
1 parent a0a3b89 commit dd4af2c

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
ChangeLog
22
=========
33

4-
0.4.2 (2015-??-??)
5-
-----------------
4+
0.4.2 (2015-03-20)
5+
------------------
66

77
* Removed `constants.php` again. They messed with PHPUnit and don't really
88
provide a great benefit.
9+
* #41: Correctly handle self-closing xml elements.
910

1011

1112
0.4.1 (2015-03-19)
12-
-----------------
13+
------------------
1314

1415
* #40: An element with an empty namespace (xmlns="") is not allowed to have a
1516
prefix. This is now fixed.

lib/Element/XmlFragment.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ function xmlSerialize(Writer $writer) {
9696
break;
9797
}
9898
}
99+
if ($reader->isEmptyElement) {
100+
$writer->endElement();
101+
}
99102
break;
100103
case Reader::CDATA :
101104
case Reader::TEXT :

tests/Sabre/XML/Element/XmlFragmentTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ function xmlProvider() {
9393
'<foo:element xmlns:foo="http://example.org/ns" xmlns="http://sabredav.org/ns"><child>hello</child></foo:element>',
9494
'<x1:element xmlns:x1="http://example.org/ns"><child>hello</child></x1:element>',
9595
],
96+
[
97+
'<foo:element xmlns:foo="http://example.org/ns"><child/></foo:element>',
98+
'<foo:element xmlns:foo="http://example.org/ns" xmlns="http://sabredav.org/ns"><child/></foo:element>',
99+
'<x1:element xmlns:x1="http://example.org/ns"><child/></x1:element>',
100+
],
96101
];
97102

98103
}

0 commit comments

Comments
 (0)