Fix: redirect to referrer after bookmark deletion

Except if the referer points to a permalink (which has been deleted).

Fixes #1622
This commit is contained in:
ArthurHoaro 2020-11-05 16:14:22 +01:00
parent 38b55fbf3d
commit 330ac859fb
2 changed files with 7 additions and 3 deletions

View file

@ -66,8 +66,8 @@ public function deleteBookmark(Request $request, Response $response): Response
return $response->write('<script>self.close();</script>');
}
// Don't redirect to where we were previously because the datastore has changed.
return $this->redirect($response, '/');
// Don't redirect to permalink after deletion.
return $this->redirectFromReferer($request, $response, ['shaare/']);
}
/**

View file

@ -38,6 +38,8 @@ public function testDeleteSingleBookmark(): void
{
$parameters = ['id' => '123'];
$this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/shaare/abcdef';
$request = $this->createMock(Request::class);
$request
->method('getParam')
@ -90,6 +92,8 @@ public function testDeleteMultipleBookmarks(): void
{
$parameters = ['id' => '123 456 789'];
$this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/?searchtags=abcdef';
$request = $this->createMock(Request::class);
$request
->method('getParam')
@ -152,7 +156,7 @@ public function testDeleteMultipleBookmarks(): void
$result = $this->controller->deleteBookmark($request, $response);
static::assertSame(302, $result->getStatusCode());
static::assertSame(['/subfolder/'], $result->getHeader('location'));
static::assertSame(['/subfolder/?searchtags=abcdef'], $result->getHeader('location'));
}
/**