diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 9adc4c29b..8c7c25779 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -615,7 +615,7 @@ class ConfigController extends AbstractController $this->entityManager->persist($user); $this->entityManager->flush(); - return $this->redirect($request->headers->get('referer')); + return $this->redirect($request->getSession()->get('prevUrl')); } /** diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index f26fe1b48..655217c95 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -128,7 +128,7 @@ class EntryController extends AbstractController $this->entityManager->flush(); } - $redirectUrl = $this->redirectHelper->to($request->headers->get('referer')); + $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl')); return $this->redirect($redirectUrl); } @@ -390,6 +390,7 @@ class EntryController extends AbstractController public function viewAction(Entry $entry) { $this->checkUserAction($entry); + $this->get('session')->set('prevUrl', $this->generateUrl('view', ['id' => $entry->getId()])); return $this->render( '@WallabagCore/Entry/entry.html.twig', @@ -451,7 +452,7 @@ class EntryController extends AbstractController $message ); - $redirectUrl = $this->redirectHelper->to($request->headers->get('referer')); + $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl')); return $this->redirect($redirectUrl); } @@ -481,7 +482,7 @@ class EntryController extends AbstractController $message ); - $redirectUrl = $this->redirectHelper->to($request->headers->get('referer')); + $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl')); return $this->redirect($redirectUrl); } @@ -517,8 +518,8 @@ class EntryController extends AbstractController ); // don't redirect user to the deleted entry (check that the referer doesn't end with the same url) - $referer = $request->headers->get('referer'); - $to = (1 !== preg_match('#' . $url . '$#i', $referer) ? $referer : null); + $prev = $request->getSession()->get('prevUrl'); + $to = (1 !== preg_match('#' . $url . '$#i', $prev) ? $prev : null); $redirectUrl = $this->redirectHelper->to($to); @@ -616,6 +617,7 @@ class EntryController extends AbstractController { $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : ''); $currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : ''); + $request->getSession()->set('prevUrl', $request->getRequestUri()); $formOptions = []; diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index c15b6947d..6e147df98 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -104,7 +104,7 @@ class TagController extends AbstractController $this->entityManager->flush(); } - $redirectUrl = $this->redirectHelper->to($request->headers->get('referer'), '', true); + $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true); return $this->redirect($redirectUrl); } @@ -185,7 +185,7 @@ class TagController extends AbstractController $form = $this->createForm(RenameTagType::class, new Tag()); $form->handleRequest($request); - $redirectUrl = $this->redirectHelper->to($request->headers->get('referer'), '', true); + $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true); if ($form->isSubmitted() && $form->isValid()) { $newTag = new Tag(); @@ -257,7 +257,7 @@ class TagController extends AbstractController $this->entityManager->flush(); } - return $this->redirect($this->redirectHelper->to($request->headers->get('referer'), '', true)); + return $this->redirect($this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true)); } /** @@ -279,8 +279,7 @@ class TagController extends AbstractController $this->entityManager->remove($tag); $this->entityManager->flush(); } - - $redirectUrl = $this->redirectHelper->to($request->headers->get('referer'), '', true); + $redirectUrl = $this->redirectHelper->to($request->getSession()->get('prevUrl'), '', true); return $this->redirect($redirectUrl); } diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 9c2247f7f..fe21693a2 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -124,7 +124,7 @@ class TagControllerTest extends WallabagCoreTestCase // We make a first request to set an history and test redirection after tag deletion $client->request('GET', '/view/' . $entry->getId()); - $entryUri = $client->getRequest()->getUri(); + $entryUri = $client->getRequest()->getRequestUri(); $client->request('GET', '/remove-tag/' . $entry->getId() . '/' . $tag->getId()); $this->assertSame(302, $client->getResponse()->getStatusCode());