From 7a9a5ec0298df4afb51233635a9fb0bbaec113bf Mon Sep 17 00:00:00 2001 From: Evert Pot Date: Tue, 22 Mar 2016 23:54:32 -0400 Subject: [PATCH 1/3] Finaly some sanity in the href stuff. --- lib/CalDAV/Plugin.php | 9 +-- lib/CalDAV/Schedule/Plugin.php | 7 +- lib/CalDAV/SharingPlugin.php | 5 +- lib/CalDAV/Subscriptions/Subscription.php | 2 +- lib/CardDAV/Plugin.php | 5 +- lib/DAV/Xml/Property/Href.php | 17 +---- lib/DAV/Xml/Property/LocalHref.php | 48 +++++++++++++ tests/Sabre/DAV/Xml/Property/HrefTest.php | 29 -------- .../Sabre/DAV/Xml/Property/LocalHrefTest.php | 69 +++++++++++++++++++ 9 files changed, 136 insertions(+), 55 deletions(-) create mode 100644 lib/DAV/Xml/Property/LocalHref.php create mode 100644 tests/Sabre/DAV/Xml/Property/LocalHrefTest.php diff --git a/lib/CalDAV/Plugin.php b/lib/CalDAV/Plugin.php index 7979856fd7..0a240f7b29 100644 --- a/lib/CalDAV/Plugin.php +++ b/lib/CalDAV/Plugin.php @@ -7,6 +7,7 @@ use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\MkCol; use Sabre\DAV\Xml\Property\Href; +use Sabre\DAV\Xml\Property\LocalHref; use Sabre\DAVACL; use Sabre\VObject; use Sabre\HTTP; @@ -342,7 +343,7 @@ function propFind(DAV\PropFind $propFind, DAV\INode $node) { $calendarHomePath = $this->getCalendarHomeForPrincipal($principalUrl); if (is_null($calendarHomePath)) return null; - return new Href($calendarHomePath . '/'); + return new LocalHref($calendarHomePath . '/'); }); // The calendar-user-address-set property is basically mapped to @@ -350,7 +351,7 @@ function propFind(DAV\PropFind $propFind, DAV\INode $node) { $propFind->handle('{' . self::NS_CALDAV . '}calendar-user-address-set', function() use ($node) { $addresses = $node->getAlternateUriSet(); $addresses[] = $this->server->getBaseUri() . $node->getPrincipalUrl() . '/'; - return new Href($addresses, false); + return new LocalHref($addresses); }); // For some reason somebody thought it was a good idea to add // another one of these properties. We're supporting it too. @@ -395,8 +396,8 @@ function propFind(DAV\PropFind $propFind, DAV\INode $node) { } - $propFind->set($propRead, new Href($readList)); - $propFind->set($propWrite, new Href($writeList)); + $propFind->set($propRead, new LocalHref($readList)); + $propFind->set($propWrite, new LocalHref($writeList)); } diff --git a/lib/CalDAV/Schedule/Plugin.php b/lib/CalDAV/Schedule/Plugin.php index 27f2a36839..90662751ca 100644 --- a/lib/CalDAV/Schedule/Plugin.php +++ b/lib/CalDAV/Schedule/Plugin.php @@ -9,6 +9,7 @@ use Sabre\DAV\PropPatch; use Sabre\DAV\INode; use Sabre\DAV\Xml\Property\Href; +use Sabre\DAV\Xml\Property\LocalHref; use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; use Sabre\VObject; @@ -215,7 +216,7 @@ function propFind(PropFind $propFind, INode $node) { } $outboxPath = $calendarHomePath . '/outbox/'; - return new Href($outboxPath); + return new LocalHref($outboxPath); }); // schedule-inbox-URL property @@ -227,7 +228,7 @@ function propFind(PropFind $propFind, INode $node) { } $inboxPath = $calendarHomePath . '/inbox/'; - return new Href($inboxPath); + return new LocalHref($inboxPath); }); @@ -256,7 +257,7 @@ function propFind(PropFind $propFind, INode $node) { if (!isset($child[200][$sccs]) || in_array('VEVENT', $child[200][$sccs]->getValue())) { // Either there is no supported-calendar-component-set // (which is fine) or we found one that supports VEVENT. - return new Href($child['href']); + return new LocalHref($child['href']); } } diff --git a/lib/CalDAV/SharingPlugin.php b/lib/CalDAV/SharingPlugin.php index 5b181c72d5..7b9f67b2fb 100644 --- a/lib/CalDAV/SharingPlugin.php +++ b/lib/CalDAV/SharingPlugin.php @@ -4,6 +4,7 @@ use Sabre\DAV; use Sabre\DAV\Xml\Property\Href; +use Sabre\DAV\Xml\Property\LocalHref; use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; @@ -127,7 +128,7 @@ function propFindEarly(DAV\PropFind $propFind, DAV\INode $node) { if ($node instanceof ISharedCalendar) { $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}shared-url', function() use ($node) { - return new Href( + return new LocalHref( $node->getSharedUrl() ); }); @@ -332,7 +333,7 @@ function httpPost(RequestInterface $request, ResponseInterface $response) { $writer->openMemory(); $writer->startDocument(); $writer->startElement('{' . Plugin::NS_CALENDARSERVER . '}shared-as'); - $writer->write(new Href($url)); + $writer->write(new LocalHref($url)); $writer->endElement(); $response->setHeader('Content-Type', 'application/xml'); $response->setBody($writer->outputMemory()); diff --git a/lib/CalDAV/Subscriptions/Subscription.php b/lib/CalDAV/Subscriptions/Subscription.php index 1e4848c53c..c4ac310428 100644 --- a/lib/CalDAV/Subscriptions/Subscription.php +++ b/lib/CalDAV/Subscriptions/Subscription.php @@ -154,7 +154,7 @@ function getProperties($properties) { switch ($prop) { case '{http://calendarserver.org/ns/}source' : - $r[$prop] = new Href($this->subscriptionInfo['source'], false); + $r[$prop] = new Href($this->subscriptionInfo['source']); break; default : if (array_key_exists($prop, $this->subscriptionInfo)) { diff --git a/lib/CardDAV/Plugin.php b/lib/CardDAV/Plugin.php index b8bded098d..d1bc2f71bd 100644 --- a/lib/CardDAV/Plugin.php +++ b/lib/CardDAV/Plugin.php @@ -5,6 +5,7 @@ use Sabre\DAV; use Sabre\DAV\Exception\ReportNotSupported; use Sabre\DAV\Xml\Property\Href; +use Sabre\DAV\Xml\Property\LocalHref; use Sabre\DAVACL; use Sabre\HTTP; use Sabre\HTTP\RequestInterface; @@ -156,11 +157,11 @@ function propFindEarly(DAV\PropFind $propFind, DAV\INode $node) { $path = $propFind->getPath(); $propFind->handle('{' . self::NS_CARDDAV . '}addressbook-home-set', function() use ($path) { - return new Href($this->getAddressBookHomeForPrincipal($path) . '/'); + return new LocalHref($this->getAddressBookHomeForPrincipal($path) . '/'); }); if ($this->directories) $propFind->handle('{' . self::NS_CARDDAV . '}directory-gateway', function() { - return new Href($this->directories); + return new LocalHref($this->directories); }); } diff --git a/lib/DAV/Xml/Property/Href.php b/lib/DAV/Xml/Property/Href.php index 538e98d0f9..0027f72e19 100644 --- a/lib/DAV/Xml/Property/Href.php +++ b/lib/DAV/Xml/Property/Href.php @@ -7,6 +7,7 @@ use Sabre\Xml\Element; use Sabre\Xml\Reader; use Sabre\Xml\Writer; +use Sabre\Uri; /** * Href property @@ -31,13 +32,6 @@ class Href implements Element, HtmlOutput { */ protected $hrefs; - /** - * Automatically prefix the url with the server base directory - * - * @var bool - */ - protected $autoPrefix = true; - /** * Constructor * @@ -47,16 +41,13 @@ class Href implements Element, HtmlOutput { * and not relative to the servers base uri. * * @param string|string[] $href - * @param bool $autoPrefix */ - function __construct($hrefs, $autoPrefix = true) { + function __construct($hrefs) { if (is_string($hrefs)) { $hrefs = [$hrefs]; } $this->hrefs = $hrefs; - $this->autoPrefix = $autoPrefix; - } @@ -104,9 +95,7 @@ function getHrefs() { function xmlSerialize(Writer $writer) { foreach ($this->getHrefs() as $href) { - if ($this->autoPrefix) { - $href = $writer->contextUri . \Sabre\HTTP\encodePath($href); - } + $href = Uri\resolve($writer->contextUri, $href); $writer->writeElement('{DAV:}href', $href); } diff --git a/lib/DAV/Xml/Property/LocalHref.php b/lib/DAV/Xml/Property/LocalHref.php new file mode 100644 index 0000000000..76a27b95dd --- /dev/null +++ b/lib/DAV/Xml/Property/LocalHref.php @@ -0,0 +1,48 @@ +assertXmlStringEqualsXmlString( ' /bla/path -', $xml); - - } - function testSerializeSpace() { - - $href = new Href('path alsopath'); - $this->assertEquals('path alsopath', $href->getHref()); - - $this->contextUri = '/bla/'; - - $xml = $this->write(['{DAV:}anything' => $href]); - - $this->assertXmlStringEqualsXmlString( -' -/bla/path%20alsopath -', $xml); - - } - - function testSerializeNoPrefix() { - - $href = new Href('path', false); - $this->assertEquals('path', $href->getHref()); - - $xml = $this->write(['{DAV:}anything' => $href]); - - $this->assertXmlStringEqualsXmlString( -' -path ', $xml); } diff --git a/tests/Sabre/DAV/Xml/Property/LocalHrefTest.php b/tests/Sabre/DAV/Xml/Property/LocalHrefTest.php new file mode 100644 index 0000000000..c3f69c929f --- /dev/null +++ b/tests/Sabre/DAV/Xml/Property/LocalHrefTest.php @@ -0,0 +1,69 @@ +assertEquals('path', $href->getHref()); + + } + + function testSerialize() { + + $href = new LocalHref('path'); + $this->assertEquals('path', $href->getHref()); + + $this->contextUri = '/bla/'; + + $xml = $this->write(['{DAV:}anything' => $href]); + + $this->assertXmlStringEqualsXmlString( +' +/bla/path +', $xml); + + } + function testSerializeSpace() { + + $href = new LocalHref('path alsopath'); + $this->assertEquals('path%20alsopath', $href->getHref()); + + $this->contextUri = '/bla/'; + + $xml = $this->write(['{DAV:}anything' => $href]); + + $this->assertXmlStringEqualsXmlString( +' +/bla/path%20alsopath +', $xml); + + } + function testToHtml() { + + $href = new LocalHref([ + '/foo/bar', + 'foo/bar', + 'http://example.org/bar' + ]); + + $html = new HtmlOutputHelper( + '/base/', + [] + ); + + $expected = + '/foo/bar
' . + '/base/foo/bar
' . + 'http://example.org/bar'; + $this->assertEquals($expected, $href->toHtml($html)); + + } + +} From 3bc8a62d552958bd7f4fa56fc885adcc7126a63f Mon Sep 17 00:00:00 2001 From: Evert Pot Date: Wed, 23 Mar 2016 00:00:31 -0400 Subject: [PATCH 2/3] CS --- lib/CalDAV/Plugin.php | 1 - lib/CardDAV/Plugin.php | 1 - tests/bootstrap.php | 12 ++++++------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/CalDAV/Plugin.php b/lib/CalDAV/Plugin.php index 0a240f7b29..7427551f27 100644 --- a/lib/CalDAV/Plugin.php +++ b/lib/CalDAV/Plugin.php @@ -6,7 +6,6 @@ use Sabre\DAV; use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\MkCol; -use Sabre\DAV\Xml\Property\Href; use Sabre\DAV\Xml\Property\LocalHref; use Sabre\DAVACL; use Sabre\VObject; diff --git a/lib/CardDAV/Plugin.php b/lib/CardDAV/Plugin.php index d1bc2f71bd..2149c7828c 100644 --- a/lib/CardDAV/Plugin.php +++ b/lib/CardDAV/Plugin.php @@ -4,7 +4,6 @@ use Sabre\DAV; use Sabre\DAV\Exception\ReportNotSupported; -use Sabre\DAV\Xml\Property\Href; use Sabre\DAV\Xml\Property\LocalHref; use Sabre\DAVACL; use Sabre\HTTP; diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 325ccd3c7f..d2c0a224fa 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -7,15 +7,15 @@ // SabreDAV tests auto loading $autoLoader->add('Sabre\\', __DIR__); // VObject tests auto loading -$autoLoader->addPsr4('Sabre\\VObject\\',__DIR__ . '/../vendor/sabre/vobject/tests/VObject'); -$autoLoader->addPsr4('Sabre\\Xml\\',__DIR__ . '/../vendor/sabre/xml/tests/Sabre/Xml'); +$autoLoader->addPsr4('Sabre\\VObject\\', __DIR__ . '/../vendor/sabre/vobject/tests/VObject'); +$autoLoader->addPsr4('Sabre\\Xml\\', __DIR__ . '/../vendor/sabre/xml/tests/Sabre/Xml'); date_default_timezone_set('UTC'); $config = [ 'SABRE_TEMPDIR' => dirname(__FILE__) . '/temp/', - 'SABRE_HASSQLITE' => in_array('sqlite',PDO::getAvailableDrivers()), - 'SABRE_HASMYSQL' => in_array('mysql',PDO::getAvailableDrivers()), + 'SABRE_HASSQLITE' => in_array('sqlite', PDO::getAvailableDrivers()), + 'SABRE_HASMYSQL' => in_array('mysql', PDO::getAvailableDrivers()), 'SABRE_MYSQLDSN' => 'mysql:host=127.0.0.1;dbname=sabredav', 'SABRE_MYSQLUSER' => 'root', 'SABRE_MYSQLPASS' => '', @@ -23,12 +23,12 @@ if (file_exists(__DIR__ . '/config.user.php')) { include __DIR__ . '/config.user.php'; - foreach($userConfig as $key=>$value) { + foreach ($userConfig as $key => $value) { $config[$key] = $value; } } -foreach($config as $key=>$value) { +foreach ($config as $key => $value) { if (!defined($key)) define($key, $value); } From 78b0570a31f6571d8e6d3dbe587acf95627b7bb1 Mon Sep 17 00:00:00 2001 From: Evert Pot Date: Wed, 23 Mar 2016 00:01:47 -0400 Subject: [PATCH 3/3] Updated changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c6a99bc79..30becd701e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ ChangeLog version you now first need to update to sabre/dav 3.1. * Removed deprecated function: `Sabre\DAV\Auth\Plugin::getCurrentUser()`. * #774: Fixes for getting free disk space on Windows. +* #801: BC break: If you were using the `Href` object before, it's behavior + now changed a bit, and `LocalHref` was added to replace the old, default + behavior of `Href`. See the migration doc for more info. 3.1.3 (????-??-??)