mirror of
https://codeberg.org/icewind/SearchDAV.git
synced 2026-06-03 17:44:06 +02:00
Merge pull request #8 from kesselb/fix/undefined-index
Prevent "Undefined index: 0" for where condition
This commit is contained in:
commit
a469e21c43
3 changed files with 66 additions and 1 deletions
|
|
@ -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'];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
30
tests/invalidwherenoprop.xml
Normal file
30
tests/invalidwherenoprop.xml
Normal 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>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue