Fixes to is-defined and is-not-defined prop-filter

Gosh, this was completely broken previously. A number of different scenarios now work.

I have used some of the state I've seen in a largish production database with the
presence of NULL and empty strings. I've assumed that empty string should be treated
as is-not-defined. Happy to be talked out of that.

Closes #281.
This commit is contained in:
Andrew Ruthven 2023-02-04 18:38:17 +13:00 committed by Florian Schlichting
parent 7349944fbc
commit 4a380b12a2
19 changed files with 611 additions and 18 deletions

View File

@ -98,25 +98,67 @@ function SqlFilterFragment( $filter, $components, $property = null, $parameter =
return false; // Not handled in SQL
}
if ( isset( $property ) ) {
switch( $property ) {
# $property may include the table name, remove that for the switch.
if (strpos($property, '.')) {
$base_property = explode('.', $property)[1];
} else {
$base_property = $property;
}
switch( $base_property ) {
case 'created':
case 'completed': /** @todo when it can be handled in the SQL - see around line 200 below */
case 'dtend':
case 'dtstamp':
case 'dtstart':
case 'due':
if ( ! $target_collection->IsSchedulingCollection() ) {
$property_defined_match = "IS NOT NULL";
if ($not_defined == "not ") {
// "not IS NOT NULL" is a syntax error in SQL.
$property_defined_match = "IS NULL";
$not_defined = '';
} else {
$property_defined_match = "IS NOT NULL";
}
}
break;
case 'priority':
$property_defined_match = "IS NOT NULL";
case 'status':
if ($not_defined == "not ") {
// "not IS NOT NULL" is a syntax error in SQL.
$property_defined_match = "IS NULL";
$not_defined = '';
} else {
$property_defined_match = "IS NOT NULL";
}
break;
// These may be null or have the empty string, so we need a more complicated query.
case 'location':
case 'summary':
case 'url':
if ($not_defined == "not ") {
// "not IS NOT NULL" is a syntax error in SQL.
$property_defined_match = "IS NULL";
$condition = 'OR';
} else {
$property_defined_match = "IS NOT NULL";
$condition = 'AND';
}
$sql .= sprintf(" AND (%s %s %s %s %sLIKE '_%%') ", $property, $property_defined_match, $condition, $property, $not_defined);
$property_defined_match = null;
break;
default:
$property_defined_match = "LIKE '_%'"; // i.e. contains a single character or more
}
$sql .= sprintf( "AND %s %s%s ", $property, $not_defined, $property_defined_match );
if (isset($property_defined_match)) {
$sql .= sprintf( "AND %s %s%s ", $property, $not_defined, $property_defined_match );
}
}
break;

View File

@ -1,10 +0,0 @@
HTTP/1.1 207 Multi-Status
Date: Dow, 01 Jan 2000 00:00:00 GMT
DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule
DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy
ETag: "07474790757c5e1b526ce4901889d6d3"
Content-Length: 68
Content-Type: text/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:"/>

View File

@ -0,0 +1,9 @@
HTTP/1.1 201 Created
Date: Dow, 01 Jan 2000 00:00:00 GMT
DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule
DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy
Cache-Control: no-cache
Content-Length: 0
Content-Type: text/plain; charset="utf-8"

View File

@ -0,0 +1,33 @@
#
# Make a new collect for events
#
TYPE=MKCALENDAR
URL=http://regression.host/caldav.php/user1/
HEADER=User-Agent: DAViCal test/1.12.0
HEADER=Content-Type: text/xml; charset=utf-8
HEADER=Accept: */*
HEADER=Content-Type: application/xml; charset="utf-8"
HEAD
BEGINDATA
<?xml version="1.0" encoding="utf-8" ?>
<C:mkcalendar xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:set>
<D:prop>
<D:displayname>Events_tests</D:displayname>
<C:supported-calendar-component-set>
<C:comp name="VEVENT"/>
<C:comp name="VTODO"/>
<C:comp name="VTIMEZONE"/>
<C:comp name="VFREEBUSY"/>
</C:supported-calendar-component-set>
</D:prop>
</D:set>
</C:mkcalendar>
ENDDATA
QUERY
SELECT * FROM collection WHERE dav_name = '/user1/Events tests';
ENDQUERY

View File

@ -0,0 +1,40 @@
BEGIN:VCALENDAR
PRODID:-//davical.org//NONSGML AWL Calendar//EN
VERSION:2.0
CALSCALE:GREGORIAN
X-WR-CALNAME:mir-test
BEGIN:VTODO
UID:19970901T130000Z-123405@host.com
DTSTAMP:19970901T130000Z
DTSTART:19970415T133000Z
DUE:19970516T045959Z
SUMMARY:Status is not set
CLASS:CONFIDENTIAL
CATEGORIES:FAMILY,FINANCE
PRIORITY:1
END:VTODO
BEGIN:VTODO
UID:19920901T130000Z-123407@host.com
DTSTAMP:19920901T130000Z
DTSTART:19920415T133000Z
DUE:19920516T045959Z
SUMMARY:Status is set to COMPLETED, empty URL
CLASS:CONFIDENTIAL
CATEGORIES:FAMILY,FINANCE
STATUS:COMPLETED
URL:
COMPLETED:19940101T000000Z
PRIORITY:1
END:VTODO
BEGIN:VTODO
UID:19920901T130000Z-123408@host.com
DTSTAMP:19920901T130000Z
DTSTART:19920415T133000Z
SUMMARY:Status is IN-PROCESS, URL is set
STATUS:IN-PROCESS
URL:https://www.davical.org
CLASS:CONFIDENTIAL
CATEGORIES:FAMILY,FINANCE
PRIORITY:1
END:VTODO
END:VCALENDAR

View File

@ -0,0 +1,7 @@
HTTP/1.1 200 OK
Date: Dow, 01 Jan 2000 00:00:00 GMT
DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule
DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy
Content-Length: 0
Content-Type: text/plain; charset="utf-8"

View File

@ -0,0 +1,14 @@
#
# PUT a calendar collection to user1 so we have relevant events
#
# There is no CalDAV defined behaviour for this.
#
TYPE=PUT
URL=http://regression.host/caldav.php/user1/events/
HEADER=User-Agent: DAViCal Testing/1.12.x
HEADER=Content-Type: text/calendar; charset=utf-8
AUTH=user1:user1
HEAD
DATA=2500-is-defined-Setup-PUT-collection

View File

@ -0,0 +1,35 @@
HTTP/1.1 207 Multi-Status
Date: Dow, 01 Jan 2000 00:00:00 GMT
DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule
DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy
ETag: "59f93496e3ef79135478f26203487b2c"
Content-Length: 683
Content-Type: text/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<response>
<href>/caldav.php/user1/events/19970901T130000Z-123405host.com.ics</href>
<propstat>
<prop>
<C:calendar-data>BEGIN:VCALENDAR
PRODID:-//davical.org//NONSGML AWL Calendar//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VTODO
UID:19970901T130000Z-123405@host.com
DTSTAMP:19970901T130000Z
DTSTART:19970415T133000Z
DUE:19970516T045959Z
SUMMARY:Status is not set
CLASS:CONFIDENTIAL
CATEGORIES:FAMILY,FINANCE
PRIORITY:1
END:VTODO
END:VCALENDAR
</C:calendar-data>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>

View File

@ -1,13 +1,12 @@
#
# not-defined REPORT
# is-not-defined REPORT
#
# Regression test for https://gitlab.com/davical-project/davical/-/issues/279
#
# Returns nothing, but at least we don't get a fatal error now.
# XXX: Changed to be a test that returns records
# Neither COMPLETED or STATUS is set
#
TYPE=REPORT
URL=http://regression.host/caldav.php/user1/home/
URL=http://regression.host/caldav.php/user1/events/
HEADER=Content-Type: text/xml; charset="UTF-8"
HEADER=Depth: 0
HEAD

View File

@ -0,0 +1,63 @@
HTTP/1.1 207 Multi-Status
Date: Dow, 01 Jan 2000 00:00:00 GMT
DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule
DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy
ETag: "28313224701803b7f45afe7d04f4c08d"
Content-Length: 1357
Content-Type: text/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<response>
<href>/caldav.php/user1/events/19920901T130000Z-123407host.com.ics</href>
<propstat>
<prop>
<C:calendar-data>BEGIN:VCALENDAR
PRODID:-//davical.org//NONSGML AWL Calendar//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VTODO
UID:19920901T130000Z-123407@host.com
DTSTAMP:19920901T130000Z
DTSTART:19920415T133000Z
DUE:19920516T045959Z
SUMMARY:Status is set to COMPLETED, empty URL
CLASS:CONFIDENTIAL
CATEGORIES:FAMILY,FINANCE
STATUS:COMPLETED
URL:
COMPLETED:19940101T000000Z
PRIORITY:1
END:VTODO
END:VCALENDAR
</C:calendar-data>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/caldav.php/user1/events/19920901T130000Z-123408host.com.ics</href>
<propstat>
<prop>
<C:calendar-data>BEGIN:VCALENDAR
PRODID:-//davical.org//NONSGML AWL Calendar//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VTODO
UID:19920901T130000Z-123408@host.com
DTSTAMP:19920901T130000Z
DTSTART:19920415T133000Z
SUMMARY:Status is IN-PROCESS, URL is set
STATUS:IN-PROCESS
URL:https://www.davical.org
CLASS:CONFIDENTIAL
CATEGORIES:FAMILY,FINANCE
PRIORITY:1
END:VTODO
END:VCALENDAR
</C:calendar-data>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>

View File

@ -0,0 +1,33 @@
#
# is-defined REPORT
#
# Regression test for https://gitlab.com/davical-project/davical/-/issues/279
#
# Check that STATUS is defined.
#
TYPE=REPORT
URL=http://regression.host/caldav.php/user1/events/
HEADER=Content-Type: text/xml; charset="UTF-8"
HEADER=Depth: 0
HEAD
BEGINDATA
<?xml version='1.0' encoding='utf-8'?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VTODO">
<C:prop-filter name="STATUS">
<C:is-defined/>
</C:prop-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>
ENDDATA

View File

@ -0,0 +1,36 @@
HTTP/1.1 207 Multi-Status
Date: Dow, 01 Jan 2000 00:00:00 GMT
DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule
DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy
ETag: "f6abdaed27780f116d7fc410df5fac23"
Content-Length: 724
Content-Type: text/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<response>
<href>/caldav.php/user1/events/19920901T130000Z-123408host.com.ics</href>
<propstat>
<prop>
<C:calendar-data>BEGIN:VCALENDAR
PRODID:-//davical.org//NONSGML AWL Calendar//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VTODO
UID:19920901T130000Z-123408@host.com
DTSTAMP:19920901T130000Z
DTSTART:19920415T133000Z
SUMMARY:Status is IN-PROCESS, URL is set
STATUS:IN-PROCESS
URL:https://www.davical.org
CLASS:CONFIDENTIAL
CATEGORIES:FAMILY,FINANCE
PRIORITY:1
END:VTODO
END:VCALENDAR
</C:calendar-data>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>

View File

@ -0,0 +1,33 @@
#
# is-defined REPORT
#
# Regression test for https://gitlab.com/davical-project/davical/-/issues/279
#
# Check that URL is defined.
#
TYPE=REPORT
URL=http://regression.host/caldav.php/user1/events/
HEADER=Content-Type: text/xml; charset="UTF-8"
HEADER=Depth: 0
HEAD
BEGINDATA
<?xml version='1.0' encoding='utf-8'?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VTODO">
<C:prop-filter name="URL">
<C:is-defined/>
</C:prop-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>
ENDDATA

View File

@ -0,0 +1,62 @@
HTTP/1.1 207 Multi-Status
Date: Dow, 01 Jan 2000 00:00:00 GMT
DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule
DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy
ETag: "cc87613d28223c8c0a0aa0a10b79d521"
Content-Length: 1316
Content-Type: text/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<response>
<href>/caldav.php/user1/events/19970901T130000Z-123405host.com.ics</href>
<propstat>
<prop>
<C:calendar-data>BEGIN:VCALENDAR
PRODID:-//davical.org//NONSGML AWL Calendar//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VTODO
UID:19970901T130000Z-123405@host.com
DTSTAMP:19970901T130000Z
DTSTART:19970415T133000Z
DUE:19970516T045959Z
SUMMARY:Status is not set
CLASS:CONFIDENTIAL
CATEGORIES:FAMILY,FINANCE
PRIORITY:1
END:VTODO
END:VCALENDAR
</C:calendar-data>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/caldav.php/user1/events/19920901T130000Z-123407host.com.ics</href>
<propstat>
<prop>
<C:calendar-data>BEGIN:VCALENDAR
PRODID:-//davical.org//NONSGML AWL Calendar//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VTODO
UID:19920901T130000Z-123407@host.com
DTSTAMP:19920901T130000Z
DTSTART:19920415T133000Z
DUE:19920516T045959Z
SUMMARY:Status is set to COMPLETED, empty URL
CLASS:CONFIDENTIAL
CATEGORIES:FAMILY,FINANCE
STATUS:COMPLETED
URL:
COMPLETED:19940101T000000Z
PRIORITY:1
END:VTODO
END:VCALENDAR
</C:calendar-data>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>

View File

@ -0,0 +1,33 @@
#
# is-not-defined REPORT
#
# Regression test for https://gitlab.com/davical-project/davical/-/issues/279
#
# Check that URL is not defined.
#
TYPE=REPORT
URL=http://regression.host/caldav.php/user1/events/
HEADER=Content-Type: text/xml; charset="UTF-8"
HEADER=Depth: 0
HEAD
BEGINDATA
<?xml version='1.0' encoding='utf-8'?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VTODO">
<C:prop-filter name="URL">
<C:is-not-defined/>
</C:prop-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>
ENDDATA

View File

@ -0,0 +1,62 @@
HTTP/1.1 207 Multi-Status
Date: Dow, 01 Jan 2000 00:00:00 GMT
DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule
DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy
ETag: "cc87613d28223c8c0a0aa0a10b79d521"
Content-Length: 1316
Content-Type: text/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<response>
<href>/caldav.php/user1/events/19970901T130000Z-123405host.com.ics</href>
<propstat>
<prop>
<C:calendar-data>BEGIN:VCALENDAR
PRODID:-//davical.org//NONSGML AWL Calendar//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VTODO
UID:19970901T130000Z-123405@host.com
DTSTAMP:19970901T130000Z
DTSTART:19970415T133000Z
DUE:19970516T045959Z
SUMMARY:Status is not set
CLASS:CONFIDENTIAL
CATEGORIES:FAMILY,FINANCE
PRIORITY:1
END:VTODO
END:VCALENDAR
</C:calendar-data>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/caldav.php/user1/events/19920901T130000Z-123407host.com.ics</href>
<propstat>
<prop>
<C:calendar-data>BEGIN:VCALENDAR
PRODID:-//davical.org//NONSGML AWL Calendar//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VTODO
UID:19920901T130000Z-123407@host.com
DTSTAMP:19920901T130000Z
DTSTART:19920415T133000Z
DUE:19920516T045959Z
SUMMARY:Status is set to COMPLETED, empty URL
CLASS:CONFIDENTIAL
CATEGORIES:FAMILY,FINANCE
STATUS:COMPLETED
URL:
COMPLETED:19940101T000000Z
PRIORITY:1
END:VTODO
END:VCALENDAR
</C:calendar-data>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>

View File

@ -0,0 +1,33 @@
#
# is-defined REPORT
#
# Regression test for https://gitlab.com/davical-project/davical/-/issues/279
#
# Check that DUE is defined.
#
TYPE=REPORT
URL=http://regression.host/caldav.php/user1/events/
HEADER=Content-Type: text/xml; charset="UTF-8"
HEADER=Depth: 0
HEAD
BEGINDATA
<?xml version='1.0' encoding='utf-8'?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VTODO">
<C:prop-filter name="DUE">
<C:is-defined/>
</C:prop-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>
ENDDATA

View File

@ -0,0 +1,36 @@
HTTP/1.1 207 Multi-Status
Date: Dow, 01 Jan 2000 00:00:00 GMT
DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule
DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy
ETag: "f6abdaed27780f116d7fc410df5fac23"
Content-Length: 724
Content-Type: text/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<response>
<href>/caldav.php/user1/events/19920901T130000Z-123408host.com.ics</href>
<propstat>
<prop>
<C:calendar-data>BEGIN:VCALENDAR
PRODID:-//davical.org//NONSGML AWL Calendar//EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VTODO
UID:19920901T130000Z-123408@host.com
DTSTAMP:19920901T130000Z
DTSTART:19920415T133000Z
SUMMARY:Status is IN-PROCESS, URL is set
STATUS:IN-PROCESS
URL:https://www.davical.org
CLASS:CONFIDENTIAL
CATEGORIES:FAMILY,FINANCE
PRIORITY:1
END:VTODO
END:VCALENDAR
</C:calendar-data>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>

View File

@ -0,0 +1,33 @@
#
# is-not-defined REPORT
#
# Regression test for https://gitlab.com/davical-project/davical/-/issues/279
#
# Check that DUE is not defined.
#
TYPE=REPORT
URL=http://regression.host/caldav.php/user1/events/
HEADER=Content-Type: text/xml; charset="UTF-8"
HEADER=Depth: 0
HEAD
BEGINDATA
<?xml version='1.0' encoding='utf-8'?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VTODO">
<C:prop-filter name="DUE">
<C:is-not-defined/>
</C:prop-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>
ENDDATA