From b247f360f559a90fc5bbb75ca9b9e38b108ea9d6 Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Sun, 6 Dec 2015 19:46:12 +0000 Subject: [PATCH 1/2] Enforce string for _METHOD As this could have come from SimpleXML, cast to a string. --- Slim/Http/Request.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Slim/Http/Request.php b/Slim/Http/Request.php index 926e4cd64..daacbc8e2 100644 --- a/Slim/Http/Request.php +++ b/Slim/Http/Request.php @@ -240,9 +240,9 @@ public function getMethod() $body = $this->getParsedBody(); if (is_object($body) && property_exists($body, '_METHOD')) { - $this->method = $this->filterMethod($body->_METHOD); + $this->method = $this->filterMethod((string)$body->_METHOD); } elseif (is_array($body) && isset($body['_METHOD'])) { - $this->method = $this->filterMethod($body['_METHOD']); + $this->method = $this->filterMethod((string)$body['_METHOD']); } if ($this->getBody()->eof()) { From 45e7f5bbc1f88f092d2e7533830e5a0fff19e26e Mon Sep 17 00:00:00 2001 From: Rob Allen Date: Sun, 6 Dec 2015 19:47:44 +0000 Subject: [PATCH 2/2] Ensure that withMethod() does what is expected If I call withMethod(), then I expect that what I've set to be what is set! i.e. we should not check for the magic _METHOD or the X-Http-Method-Override header if withMethod() has been called. --- Slim/Http/Request.php | 2 +- tests/Http/RequestTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Slim/Http/Request.php b/Slim/Http/Request.php index daacbc8e2..26744e525 100644 --- a/Slim/Http/Request.php +++ b/Slim/Http/Request.php @@ -286,7 +286,7 @@ public function withMethod($method) $method = $this->filterMethod($method); $clone = clone $this; $clone->originalMethod = $method; - $clone->method = null; // <-- Force method override recalculation + $clone->method = $method; return $clone; } diff --git a/tests/Http/RequestTest.php b/tests/Http/RequestTest.php index 0fc043932..d39d7a228 100644 --- a/tests/Http/RequestTest.php +++ b/tests/Http/RequestTest.php @@ -70,7 +70,7 @@ public function testWithMethod() { $request = $this->requestFactory()->withMethod('PUT'); - $this->assertAttributeEquals(null, 'method', $request); + $this->assertAttributeEquals('PUT', 'method', $request); $this->assertAttributeEquals('PUT', 'originalMethod', $request); }