From 1740c664910b1c73066e544f55b0695b9401fff6 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Mon, 19 Mar 2007 12:10:03 +1200 Subject: [PATCH] Test whether a URL without a trailing '/' is actually a collection. --- inc/CalDAVRequest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/inc/CalDAVRequest.php b/inc/CalDAVRequest.php index 4211c283..38fb7a1d 100644 --- a/inc/CalDAVRequest.php +++ b/inc/CalDAVRequest.php @@ -100,6 +100,21 @@ class CalDAVRequest $this->DoResponse( 400, translate("The calendar path contains illegal characters.") ); } + /** + * RFC2518, 5.2: URL pointing to a collection SHOULD end in '/', and if it does not then + * we SHOULD return a Content-location header with the correction... + */ + if ( !preg_match( '#/$#', $this->path ) ) { + dbg_error_log( "caldav", "Checking whether path might be a collection" ); + $qry = new PgQuery( "SELECT count(1) AS is_collection FROM collection WHERE dav_name = ?;", $this->path . '/'); + if ( $qry->Exec('caldav') && $qry->rows == 1 && ($row = $qry->Fetch()) && $row->is_collection == 1 ) { + dbg_error_log( "caldav", "Path is actually a collection - sending Content-Location header." ); + $this->path .= '/'; + header( "Content-Location: $this->path" ); + $this->_is_collection = true; + } + } + $path_split = preg_split('#/+#', $this->path ); $this->permissions = array(); if ( !isset($path_split[1]) || $path_split[1] == '' ) {