From b690d7aae12d7584c2a97f05988891f3c076e83d Mon Sep 17 00:00:00 2001 From: Gerben Date: Mon, 10 Sep 2018 19:46:30 +0200 Subject: [PATCH] Work around nextcloud's slash deduplication. --- lib/Controller/TimeGateController.php | 3 +++ lib/Controller/TimeMapController.php | 5 +++-- lib/Controller/findMementos.php | 5 ----- lib/Controller/getUrlParameter.php | 13 +++++++++++++ 4 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 lib/Controller/getUrlParameter.php diff --git a/lib/Controller/TimeGateController.php b/lib/Controller/TimeGateController.php index f39dd3e..1657946 100644 --- a/lib/Controller/TimeGateController.php +++ b/lib/Controller/TimeGateController.php @@ -3,6 +3,7 @@ namespace OCA\Memento\Controller; require_once __DIR__ . '/findMementos.php'; require_once __DIR__ . '/datetimeConversion.php'; +require_once __DIR__ . '/getUrlParameter.php'; use OCP\IRequest; use OCP\IURLGenerator; @@ -32,6 +33,8 @@ class TimeGateController extends Controller { * @NoCSRFRequired */ public function timeGate($url) { + $url = getUrlParameter('timegate'); // XXX workaround, as nextcloud corrupts the $url parameter. + $matchingMementos = findMementos($this->userFolder, $url); // Choose one of the matched mementos, if any. diff --git a/lib/Controller/TimeMapController.php b/lib/Controller/TimeMapController.php index 4ac3663..918a139 100644 --- a/lib/Controller/TimeMapController.php +++ b/lib/Controller/TimeMapController.php @@ -3,6 +3,7 @@ namespace OCA\Memento\Controller; require_once __DIR__ . '/findMementos.php'; require_once __DIR__ . '/datetimeConversion.php'; +require_once __DIR__ . '/getUrlParameter.php'; use OCP\IRequest; use OCP\IServerContainer; @@ -10,7 +11,6 @@ use OCP\IURLGenerator; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataDisplayResponse; - class TimeMapController extends Controller { private $userFolder; private $URLGenerator; @@ -32,6 +32,8 @@ class TimeMapController extends Controller { * @NoCSRFRequired */ public function timeMap($url) { + $url = getUrlParameter('timemap'); // XXX workaround, as nextcloud corrupts the $url parameter. + $matchingMementos = findMementos($this->userFolder, $url); // Build the list of links. @@ -46,7 +48,6 @@ class TimeMapController extends Controller { $lastDatetime = datetimeTimestampToString($lastMemento['datetime']); } $links = [ - // FIXME Our $url param has its duplicate slashes removed, so it looks like 'http:/abc'. "<$url>;rel=\"original\"", "<$timeGateUrl>;rel=\"timegate\"", "<$timeMapUrl>;rel=\"self\";type=\"application/link-format\"" . diff --git a/lib/Controller/findMementos.php b/lib/Controller/findMementos.php index c167747..4d3a2d6 100644 --- a/lib/Controller/findMementos.php +++ b/lib/Controller/findMementos.php @@ -91,10 +91,5 @@ function getDatetime($headElement) { function normaliseUrl($url) { // Ignore trailing slashes. Because everybody does. $url = rtrim($url, '/'); - - // HACK. Replace multiple slashes with a single one. Because Nextcloud will have already done this - // to the queried url (e.g. 'http://abc' arrives to us as 'http:/abc'). - $url = preg_replace('%/{2,}%', '/', $url); - return $url; } diff --git a/lib/Controller/getUrlParameter.php b/lib/Controller/getUrlParameter.php new file mode 100644 index 0000000..aa5dc6e --- /dev/null +++ b/lib/Controller/getUrlParameter.php @@ -0,0 +1,13 @@ +