From fca8b1dd3054c2155e17ddc1f91a47d23bc881af Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 24 Mar 2012 18:10:52 -0400 Subject: [PATCH] Fix issue where requestAction() would not strip base url. requestAction + Controller::referer() don't work well together. Stripping the base domain, and normalizing the URL gives an application request which works much better. This keeps RequestHandler more transparent when overloading redirects. Fixes #2711 --- lib/Cake/Core/Object.php | 4 +++- lib/Cake/Test/Case/Core/ObjectTest.php | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Core/Object.php b/lib/Cake/Core/Object.php index ed81d0435..34ea4fbe1 100644 --- a/lib/Cake/Core/Object.php +++ b/lib/Cake/Core/Object.php @@ -80,6 +80,9 @@ class Object { $data = isset($extra['data']) ? $extra['data'] : null; unset($extra['data']); + if (is_string($url) && strpos($url, FULL_BASE_URL) === 0) { + $url = Router::normalize(str_replace(FULL_BASE_URL, '', $url)); + } if (is_string($url)) { $request = new CakeRequest($url); } elseif (is_array($url)) { @@ -90,7 +93,6 @@ class Object { if (isset($data)) { $request->data = $data; } - $dispatcher = new Dispatcher(); $result = $dispatcher->dispatch($request, new CakeResponse(), $extra); Router::popRequest(); diff --git a/lib/Cake/Test/Case/Core/ObjectTest.php b/lib/Cake/Test/Case/Core/ObjectTest.php index fa5c90060..0258d0402 100644 --- a/lib/Cake/Test/Case/Core/ObjectTest.php +++ b/lib/Cake/Test/Case/Core/ObjectTest.php @@ -465,6 +465,10 @@ class ObjectTest extends CakeTestCase { $expected = 'This is a test'; $this->assertEquals($expected, $result); + $result = $this->object->requestAction(FULL_BASE_URL . '/request_action/test_request_action'); + $expected = 'This is a test'; + $this->assertEquals($expected, $result); + $result = $this->object->requestAction('/request_action/another_ra_test/2/5'); $expected = 7; $this->assertEquals($expected, $result);