handle invalid xml file

This commit is contained in:
Thomas Müller 2014-11-25 10:22:06 +01:00
parent d4f107d4dd
commit 5ce34fbaf6
3 changed files with 45 additions and 7 deletions

View File

@ -11,9 +11,17 @@
namespace OC\App;
use OCP\IURLGenerator;
use SimpleXMLElement;
class InfoParser {
/**
* @var \OC\HTTPHelper
*/
private $httpHelper;
/**
* @var IURLGenerator
*/
private $urlGenerator;
/**
* @param \OC\HTTPHelper $httpHelper
@ -25,15 +33,20 @@ class InfoParser {
}
/**
* @param string $file
* @return null|string
* @param string $file the xml file to be loaded
* @return null|array where null is an indicator for an error
*/
public function parse($file) {
if (!file_exists($file)) {
return null;
}
$xml = simplexml_load_file($file);
$loadEntities = libxml_disable_entity_loader(false);
$xml = @simplexml_load_file($file);
libxml_disable_entity_loader($loadEntities);
if ($xml == false) {
return null;
}
$array = json_decode(json_encode((array)$xml), TRUE);
if (is_null($array)) {
return null;
@ -56,15 +69,13 @@ class InfoParser {
$url = $this->urlGenerator->linkToDocs($url);
}
$array["documentation"][$key] = $url;
$array['documentation'][$key] = $url;
}
}
if (array_key_exists('types', $array)) {
foreach ($array['types'] as $type => $v) {
unset($array['types'][$type]);
$array['types'][] = $type;
}
}

View File

@ -0,0 +1,22 @@
<?xml version="1.0"?>
<info
<id>files_encryption</id>
<name>Server-side Encryption</name>
<description>
This application encrypts all files accessed by ownCloud at rest, wherever they are stored. As an example, with this application enabled, external cloud based Amazon S3 storage will be encrypted, protecting this data on storage outside of the control of the Admin. When this application is enabled for the first time, all files are encrypted as users log in and are prompted for their password. The recommended recovery key option enables recovery of files in case the key is lost.
Note that this app encrypts all files that are touched by ownCloud, so external storage providers and applications such as SharePoint will see new files encrypted when they are accessed. Encryption is based on AES 128 or 256 bit keys. More information is available in the Encryption documentation
</description>
<licence>AGPL</licence>
<author>Sam Tuke, Bjoern Schiessle, Florin Peter</author>
<requiremin>4</requiremin>
<shipped>true</shipped>
<documentation>
<user>user-encryption</user>
<admin>admin-encryption</admin>
</documentation>
<rememberlogin>false</rememberlogin>
<types>
<filesystem/>
</types>
<ocsid>166047</ocsid>
</info>

View File

@ -45,4 +45,9 @@ class InfoParser extends \PHPUnit_Framework_TestCase {
$this->assertEquals($expectedData, $data);
}
public function testParsingInvalidXml() {
$data = $this->parser->parse(OC::$SERVERROOT.'/tests/data/app/invalid-info.xml');
$this->assertNull($data);
}
}