Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addressbook-multiget with allprop causes ErrorException #952

Open
kermit-the-frog opened this issue Mar 17, 2017 · 4 comments
Open

addressbook-multiget with allprop causes ErrorException #952

kermit-the-frog opened this issue Mar 17, 2017 · 4 comments

Comments

@kermit-the-frog
Copy link

Hi,

the following request fails with the CarddavPlugin.

<?xml version="1.0" encoding="utf-8"?>
<R:addressbook-multiget xmlns:D="DAV:" xmlns:R="urn:ietf:params:xml:ns:carddav">
    <D:prop>
        <D:getetag/>
        <R:address-data>
            <C:allprop/>
        </R:address-data>
    </D:prop>
    <D:href>/PATH_TO/VCARD.vcf</D:href>
</R:addressbook-multiget>

I retrieve the following response

<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
    <s:sabredav-version>3.2.2</s:sabredav-version>
    <s:exception>ErrorException</s:exception>
    <s:message>Undefined index: name</s:message>
</d:error>

If I remove <C:allprop/> from the request, everything is working as expected.

Kind regards,
kermit-the-frog

@kermit-the-frog
Copy link
Author

Does anyone have any idea, where to dig in the source code to solve this issue?

@momo13
Copy link

momo13 commented Jun 7, 2017

I just came around this issue as well and I found the place where the exception is thrown.
It is in class AddressData in namespace Sabre\CardDAV\Xml\Filter.

    $result['addressDataProperties'] = array_map(function($element) {
        var_dump($element);
        return $element['attributes']['name'];
    }, $elems);

In our case $element['attributes'] is an empty array, while $element['name'] => "{urn:ietf:params:xml:ns:carddav}allprop"
However I haven't figured out yet, whether it would be correct to just returning $element['name'].

@momo13
Copy link

momo13 commented Jun 7, 2017

Actually my previous fix would ignore existing prop filters. So this is my current solution:

static function xmlDeserialize(Reader $reader) {

        $result = [
            'contentType' => $reader->getAttribute('content-type') ?: 'text/vcard',
            'version'     => $reader->getAttribute('version') ?: '3.0',
        ];

        $elems = (array)$reader->parseInnerTree();
        $allprop = false;

        $result['addressDataProperties'] = array_map(function($element) use (&$allprop) {
            switch ($element['name']) {
                case '{' . Plugin::NS_CARDDAV . '}allprop' :
                    $allprop = true;
                    return null;
                default:
                    if (array_key_exists('name', $element['attributes'])) {
                        return $element['attributes']['name'];
                    }
                    return null;
            }
        }, $elems);

        // addressDataProperties are used as a filter on the VCARD. If allprop is set we want
        // all data, so addressDataProperties should be null.
        if ($allprop){
            $result['addressDataProperties'] = null;
        }

        return $result;

    }

@DeepDiver1975
Copy link
Member

can you submit this change as pull request? happy to discuss the change there. THX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants