Skip to content

Commit 185447d

Browse files
committed
Merge branch 'master' of github.com:fruux/sabre-xml
2 parents 7038293 + 1b57fe3 commit 185447d

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
ChangeLog
22
=========
33

4+
1.1.0 (2015-06-29)
5+
------------------
6+
7+
* #44, #45: Catching broken and invalid XML better and throwing
8+
`Sabre\Xml\LibXMLException` whenever we encounter errors. (@stefanmajoor,
9+
@DaanBiesterbos)
10+
11+
412
1.0.0 (2015-05-25)
513
------------------
614

lib/Reader.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ function parseInnerTree(array $elementMap = null) {
112112
$this->elementMap = $elementMap;
113113
}
114114

115-
116115
// Really sorry about the silence operator, seems like I have no
117116
// choice. See:
118117
//
@@ -121,6 +120,16 @@ function parseInnerTree(array $elementMap = null) {
121120

122121
while (true) {
123122

123+
if (!$this->isValid()) {
124+
125+
$errors = libxml_get_errors();
126+
127+
if ($errors) {
128+
libxml_clear_errors();
129+
throw new LibXMLException($errors);
130+
}
131+
}
132+
124133
switch ($this->nodeType) {
125134
case self::ELEMENT :
126135
$elements[] = $this->parseCurrentElement();

tests/Sabre/Xml/ReaderTest.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ function testBrokenParserClass() {
325325
*
326326
* @expectedException Sabre\Xml\LibXMLException
327327
*/
328-
function testBrokenXML() {
328+
function testBrokenXml() {
329329

330330
$input = <<<BLA
331331
<test>
@@ -340,6 +340,33 @@ function testBrokenXML() {
340340

341341
}
342342

343+
/**
344+
* Test was added for Issue #45.
345+
*
346+
* @expectedException Sabre\Xml\LibXMLException
347+
*/
348+
function testBrokenXml2() {
349+
350+
$input = <<<XML
351+
<?xml version="1.0" encoding="UTF-8"?>
352+
<definitions>
353+
<collaboration>
354+
<participant id="sid-A33D08EB-A2DE-448F-86FE-A2B62E98818" name="Company" processRef="sid-A0A6A196-3C9A-4C69-88F6-7ED7DDFDD264">
355+
<extensionElements>
356+
<signavio:signavioMetaData metaKey="bgcolor" />
357+
""Administrative w">
358+
<extensionElements>
359+
<signavio:signavioMetaData metaKey="bgcolor" metaValue=""/>
360+
</extensionElements>
361+
</lan
362+
XML;
363+
$reader = new Reader();
364+
$reader->xml($input);
365+
$reader->parse();
366+
367+
}
368+
369+
343370
/**
344371
* @depends testMappedElement
345372
*/

0 commit comments

Comments
 (0)