From 3a06f840c38c5a88403ddc4153e31a80fe284998 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 9 Aug 2008 18:32:59 +0000 Subject: [PATCH] Adding patch from 'dardosordi' fixes RequestHandler type detection with character set. Closes #5223 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7448 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/request_handler.php | 7 ++++--- .../controller/components/request_handler.test.php | 12 ++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cake/libs/controller/components/request_handler.php b/cake/libs/controller/components/request_handler.php index c6f7f3238..f1260e71d 100644 --- a/cake/libs/controller/components/request_handler.php +++ b/cake/libs/controller/components/request_handler.php @@ -468,9 +468,10 @@ class RequestHandlerComponent extends Object { if (!$this->isPost() && !$this->isPut()) { return null; } - + + list($contentType) = explode(';', env('CONTENT_TYPE')); if ($type == null) { - return $this->mapType(env('CONTENT_TYPE')); + return $this->mapType($contentType); } elseif (is_array($type)) { foreach ($type as $t) { if ($this->requestedWith($t)) { @@ -479,7 +480,7 @@ class RequestHandlerComponent extends Object { } return false; } elseif (is_string($type)) { - return ($type == $this->mapType(env('CONTENT_TYPE'))); + return ($type == $this->mapType($contentType)); } } /** diff --git a/cake/tests/cases/libs/controller/components/request_handler.test.php b/cake/tests/cases/libs/controller/components/request_handler.test.php index 42b9d4a57..1b5e08c9a 100644 --- a/cake/tests/cases/libs/controller/components/request_handler.test.php +++ b/cake/tests/cases/libs/controller/components/request_handler.test.php @@ -177,6 +177,18 @@ class RequestHandlerComponentTest extends CakeTestCase { $this->assertTrue(is_object($this->Controller->data)); $this->assertEqual(strtolower(get_class($this->Controller->data)), 'xml'); } +/** + * testStartupCallback with charset. + * + * @return void + **/ + function testStartupCallbackCharset() { + $_SERVER['REQUEST_METHOD'] = 'PUT'; + $_SERVER['CONTENT_TYPE'] = 'application/xml; charset=UTF-8'; + $this->RequestHandler->startup($this->Controller); + $this->assertTrue(is_object($this->Controller->data)); + $this->assertEqual(strtolower(get_class($this->Controller->data)), 'xml'); + } /** * testNonAjaxRedirect method *