From be60ec177820b8e6740372af7445ae8bbee8ada3 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Sat, 4 Feb 2023 15:33:25 +1300 Subject: [PATCH] Improve on SQL syntax fix to keep logging working, and add regression test. Closes #279. --- inc/caldav-REPORT-calquery.php | 9 +++-- .../0966-REPORT-not-defined.result | 10 +++++ .../0966-REPORT-not-defined.test | 37 +++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 testing/tests/regression-suite/0966-REPORT-not-defined.result create mode 100644 testing/tests/regression-suite/0966-REPORT-not-defined.test diff --git a/inc/caldav-REPORT-calquery.php b/inc/caldav-REPORT-calquery.php index 4bdf7f9a..f41c3979 100644 --- a/inc/caldav-REPORT-calquery.php +++ b/inc/caldav-REPORT-calquery.php @@ -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; diff --git a/testing/tests/regression-suite/0966-REPORT-not-defined.result b/testing/tests/regression-suite/0966-REPORT-not-defined.result new file mode 100644 index 00000000..a9bee7e1 --- /dev/null +++ b/testing/tests/regression-suite/0966-REPORT-not-defined.result @@ -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" + + + diff --git a/testing/tests/regression-suite/0966-REPORT-not-defined.test b/testing/tests/regression-suite/0966-REPORT-not-defined.test new file mode 100644 index 00000000..679f9202 --- /dev/null +++ b/testing/tests/regression-suite/0966-REPORT-not-defined.test @@ -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 + + + + + + + + + + + + + + + + + + +ENDDATA + +