From 2b30136ae9286026af4c8be8f0311f39bbedff06 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon <blizzz@owncloud.com>
Date: Sat, 27 Feb 2016 00:59:46 +0100
Subject: [PATCH] ensure comments-href returns a value also when propfind is
 done against remote.php/files

---
 apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php    | 6 +++---
 .../tests/unit/connector/sabre/commentpropertiesplugin.php  | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php b/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php
index a8d5f771122..e9559e361b8 100644
--- a/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php
@@ -99,13 +99,13 @@ class CommentPropertiesPlugin extends ServerPlugin {
 	 */
 	public function getCommentsLink(Node $node) {
 		$href =  $this->server->getBaseUri();
-		$entryPoint = strrpos($href, '/webdav/');
+		$entryPoint = strpos($href, '/remote.php/');
 		if($entryPoint === false) {
 			// in case we end up somewhere else, unexpectedly.
 			return null;
 		}
-		$href = substr_replace($href, '/dav/', $entryPoint);
-		$href .= 'comments/files/' . rawurldecode($node->getId());
+		$commentsPart = 'dav/comments/files/' . rawurldecode($node->getId());
+		$href = substr_replace($href, $commentsPart, $entryPoint + strlen('/remote.php/'));
 		return $href;
 	}
 
diff --git a/apps/dav/tests/unit/connector/sabre/commentpropertiesplugin.php b/apps/dav/tests/unit/connector/sabre/commentpropertiesplugin.php
index f915c83c4a7..f7f87e01544 100644
--- a/apps/dav/tests/unit/connector/sabre/commentpropertiesplugin.php
+++ b/apps/dav/tests/unit/connector/sabre/commentpropertiesplugin.php
@@ -84,7 +84,8 @@ class CommentsPropertiesPlugin extends \Test\TestCase {
 	public function baseUriProvider() {
 		return [
 			['owncloud/remote.php/webdav/', '4567', 'owncloud/remote.php/dav/comments/files/4567'],
-			['owncloud/remote.php/wicked/', '4567', null]
+			['owncloud/remote.php/files/', '4567', 'owncloud/remote.php/dav/comments/files/4567'],
+			['owncloud/wicked.php/files/', '4567', null]
 		];
 	}
 
-- 
GitLab