File tree Expand file tree Collapse file tree 3 files changed +31
-7
lines changed
dev/tests/unit/testsuite/Magento/Framework/Xml
lib/internal/Magento/Framework Expand file tree Collapse file tree 3 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,13 @@ class ParserTest extends \PHPUnit_Framework_TestCase
11
11
/** @var \Magento\Framework\Xml\Parser */
12
12
protected $ parser ;
13
13
14
+ /**
15
+ * A sample invalid XML
16
+ *
17
+ * @var string
18
+ */
19
+ private static $ sampleXml = '<?xml version="1.0"?><config></onfig> ' ;
20
+
14
21
protected function setUp ()
15
22
{
16
23
$ this ->parser = new \Magento \Framework \Xml \Parser ();
@@ -31,4 +38,14 @@ public function testGetXml()
31
38
$ this ->parser ->load (__DIR__ . '/_files/data.xml ' )->xmlToArray ()
32
39
);
33
40
}
41
+
42
+ /**
43
+ * @expectedException \Magento\Framework\Exception
44
+ * @expectedExceptionMessage DOMDocument::loadXML(): Opening and ending tag mismatch
45
+ */
46
+ public function testInvalidXml ()
47
+ {
48
+ $ this ->parser ->initErrorHandler ();
49
+ $ this ->parser ->loadXML (self ::$ sampleXml );
50
+ }
34
51
}
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ class Loader
32
32
33
33
/**
34
34
* Parser
35
+ *
35
36
* @var \Magento\Framework\Xml\Parser
36
37
*/
37
38
private $ parser ;
@@ -67,8 +68,9 @@ public function load()
67
68
$ this ->parser ->loadXML ($ contents );
68
69
} catch (\Magento \Framework \Exception $ e ) {
69
70
throw new \Magento \Framework \Exception (
70
- 'Invalid Document: ' . $ file . PHP_EOL
71
- . ' Error: ' . $ e ->getMessage ()
71
+ 'Invalid Document: ' . $ file . PHP_EOL . ' Error: ' . $ e ->getMessage (),
72
+ $ e ->getCode (),
73
+ $ e
72
74
);
73
75
}
74
76
Original file line number Diff line number Diff line change @@ -156,7 +156,12 @@ public function loadXML($string)
156
156
set_error_handler ([$ this , 'errorHandler ' ]);
157
157
}
158
158
159
- $ this ->getDom ()->loadXML ($ string );
159
+ try {
160
+ $ this ->getDom ()->loadXML ($ string );
161
+ } catch (\Magento \Framework \Exception $ e ) {
162
+ restore_error_handler ();
163
+ throw new \Magento \Framework \Exception ($ e ->getMessage (), $ e ->getCode (), $ e );
164
+ }
160
165
161
166
if ($ this ->errorHandlerIsActive ) {
162
167
restore_error_handler ();
@@ -168,10 +173,10 @@ public function loadXML($string)
168
173
/**
169
174
* Custom XML lib error handler
170
175
*
171
- * @param $errorNo
172
- * @param $errorStr
173
- * @param $errorFile
174
- * @param $errorLine
176
+ * @param int $errorNo
177
+ * @param string $errorStr
178
+ * @param string $errorFile
179
+ * @param int $errorLine
175
180
* @throws \Magento\Framework\Exception
176
181
* @return void
177
182
*/
You can’t perform that action at this time.
0 commit comments