Merge pull request #8 from kesselb/fix/undefined-index

Prevent "Undefined index: 0" for where condition
This commit is contained in:
Robin Appelman 2019-11-04 10:09:57 +00:00 committed by GitHub
commit a469e21c43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 1 deletions

View file

@ -76,7 +76,7 @@ class Operator implements XmlDeserializable {
if ($reader->nodeType === Reader::ELEMENT) { if ($reader->nodeType === Reader::ELEMENT) {
$argument = $reader->parseCurrentElement(); $argument = $reader->parseCurrentElement();
if ($argument['name'] === '{DAV:}prop') { if ($argument['name'] === '{DAV:}prop') {
$operator->arguments[] = $argument['value'][0]; $operator->arguments[] = $argument['value'][0] ?? '';
} else { } else {
$operator->arguments[] = $argument['value']; $operator->arguments[] = $argument['value'];
} }

View file

@ -491,4 +491,39 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals(400, $response->getStatus()); $this->assertEquals(400, $response->getStatus());
} }
public function testSearchQueryInvalidWhereNoProp() {
$this->searchBackend->expects($this->any())
->method('getArbiterPath')
->willReturn('foo');
$plugin = new SearchPlugin($this->searchBackend);
$server = new Server();
$plugin->initialize($server);
$request = new Request('SEARCH', '/index.php/foo', [
'Content-Type' => 'text/xml'
]);
$request->setBaseUrl('/index.php');
$request->setBody(fopen(__DIR__ . '/invalidwherenoprop.xml', 'r'));
$response = new Response();
$this->searchBackend->expects($this->any())
->method('isValidScope')
->willReturn(true);
$this->searchBackend->expects($this->never())
->method('search');
$this->searchBackend->expects($this->any())
->method('getPropertyDefinitionsForScope')
->willReturn([
new SearchPropertyDefinition('{http://ns.nextcloud.com:}fileid', false, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
]);
$plugin->searchHandler($request, $response);
$this->assertEquals(400, $response->getStatus());
}
} }

View file

@ -0,0 +1,30 @@
<?xml version="1.0"?>
<d:searchrequest xmlns:d="DAV:" xmlns:oc="http://ns.nextcloud.com">
<d:basicsearch>
<d:select>
<d:prop>
<d:getcontentlength/>
</d:prop>
</d:select>
<d:from>
<d:scope>
<d:href>/container1/</d:href>
<d:depth>infinity</d:depth>
</d:scope>
</d:from>
<d:where>
<d:gt>
<d:prop />
<d:literal />
</d:gt>
</d:where>
<d:orderby>
<d:order>
<d:prop>
<d:getcontentlength/>
</d:prop>
<d:ascending/>
</d:order>
</d:orderby>
</d:basicsearch>
</d:searchrequest>