Improve on SQL syntax fix to keep logging working, and add regression test.

Closes #279.
This commit is contained in:
Andrew Ruthven 2023-02-04 15:33:25 +13:00
parent 6e6ff6b115
commit be60ec1778
3 changed files with 53 additions and 3 deletions

View File

@ -86,13 +86,16 @@ function SqlFilterFragment( $filter, $components, $property = null, $parameter =
dbg_error_log("calquery", "Processing $tag into SQL - %d, '%s', %d\n", count($components), $property, isset($parameter) );
$not_defined = "";
$not_defined_log = "";
switch( $tag ) {
case 'urn:ietf:params:xml:ns:caldav:is-not-defined':
$not_defined = "not"; // then fall through to IS-DEFINED case
$not_defined = "not "; // for SQL
$not_defined_log = "not-"; // for logging
// then fall through to IS-DEFINED case
case 'urn:ietf:params:xml:ns:caldav:is-defined':
if ( isset( $parameter ) ) {
$need_post_filter = true;
dbg_error_log("calquery", "Could not handle 'is-%sdefined' on property %s, parameter %s in SQL", $not_defined, $property, $parameter );
dbg_error_log("calquery", "Could not handle 'is-%sdefined' on property %s, parameter %s in SQL", $not_defined_log, $property, $parameter );
return false; // Not handled in SQL
}
if ( isset( $property ) ) {
@ -114,7 +117,7 @@ function SqlFilterFragment( $filter, $components, $property = null, $parameter =
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 );
$sql .= sprintf( "AND %s %s%s ", $property, $not_defined, $property_defined_match );
}
break;

View File

@ -0,0 +1,10 @@
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,37 @@
#
# 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
#
TYPE=REPORT
URL=http://regression.host/caldav.php/user1/home/
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="COMPLETED">
<C:is-not-defined/>
</C:prop-filter>
<C:prop-filter name="STATUS">
<C:is-not-defined/>
</C:prop-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>
ENDDATA