From 0fc9a2c29c489177afeecaccf4eb7ddb7ab153a7 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 25 Sep 2012 21:01:19 -0400 Subject: [PATCH 1/5] Update query building in TranslateBehavior. * Reduce duplicate checks for Alias.*. * Allow both the quoted and non quoted version of Alias.* Fixes #3210 --- lib/Cake/Model/Behavior/TranslateBehavior.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index 37eb5c426..dd1243b91 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -147,11 +147,14 @@ class TranslateBehavior extends ModelBehavior { if (empty($query['fields'])) { $addFields = $fields; } elseif (is_array($query['fields'])) { + $isAllFields = ( + in_array($Model->alias . '.' . '*', $query['fields']) || + in_array($Model->escapeField('*'), $query['fields']) + ); foreach ($fields as $key => $value) { $field = (is_numeric($key)) ? $value : $key; - if ( - in_array($Model->escapeField('*'), $query['fields']) || + $isAllFields || in_array($Model->alias . '.' . $field, $query['fields']) || in_array($field, $query['fields']) ) { From 99edef0abc3332cd833d11cd29470f6850dc73d8 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 27 Sep 2012 20:34:22 -0400 Subject: [PATCH 2/5] Re-order assertions. Group the true/false assertions. --- lib/Cake/Test/Case/Utility/ValidationTest.php | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/ValidationTest.php b/lib/Cake/Test/Case/Utility/ValidationTest.php index 73bc5e635..22afee2c9 100644 --- a/lib/Cake/Test/Case/Utility/ValidationTest.php +++ b/lib/Cake/Test/Case/Utility/ValidationTest.php @@ -1826,32 +1826,32 @@ class ValidationTest extends CakeTestCase { $this->assertTrue(Validation::url('ftp://cakephp.org/pub/cake')); $this->assertTrue(Validation::url('ftp://192.168.0.1/pub/cake')); $this->assertTrue(Validation::url('sftp://192.168.0.1/pub/cake')); - $this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake')); - $this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake')); $this->assertTrue(Validation::url('https://my.domain.com/gizmo/app?class=MySip;proc=start')); $this->assertTrue(Validation::url('www.domain.tld')); + $this->assertTrue(Validation::url('http://123456789112345678921234567893123456789412345678951234567896123.com')); + $this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2')); + $this->assertTrue(Validation::url('http://www.domain.com/blogs/parenth()eses.php')); + $this->assertTrue(Validation::url('http://www.domain.com/index.php?get=params&get2=params')); + $this->assertTrue(Validation::url('http://www.domain.com/ndex.php?get=params&get2=params#anchor')); + $this->assertTrue(Validation::url('http://www.domain.com/real%20url%20encodeing')); + $this->assertTrue(Validation::url('http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)')); + $this->assertTrue(Validation::url('http://www.cakephp.org', true)); + $this->assertTrue(Validation::url('http://example.com/~userdir/')); + $this->assertTrue(Validation::url('http://underscore_subdomain.example.org')); + $this->assertTrue(Validation::url('http://_jabber._tcp.gmail.com')); + $this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake')); + $this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake')); $this->assertFalse(Validation::url('http://w_w.domain.co_m')); $this->assertFalse(Validation::url('http://www.domain.12com')); $this->assertFalse(Validation::url('http://www.domain.longttldnotallowed')); $this->assertFalse(Validation::url('http://www.-invaliddomain.tld')); $this->assertFalse(Validation::url('http://www.domain.-invalidtld')); - $this->assertTrue(Validation::url('http://123456789112345678921234567893123456789412345678951234567896123.com')); $this->assertFalse(Validation::url('http://this-domain-is-too-loooooong-by-icann-rules-maximum-length-is-63.com')); - $this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2')); - $this->assertTrue(Validation::url('http://www.domain.com/blogs/parenth()eses.php')); - $this->assertTrue(Validation::url('http://www.domain.com/index.php?get=params&get2=params')); - $this->assertTrue(Validation::url('http://www.domain.com/ndex.php?get=params&get2=params#anchor')); - $this->assertFalse(Validation::url('http://www.domain.com/fakeenco%ode')); - $this->assertTrue(Validation::url('http://www.domain.com/real%20url%20encodeing')); - $this->assertTrue(Validation::url('http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)')); - $this->assertFalse(Validation::url('http://en.(wikipedia).org/')); - $this->assertFalse(Validation::url('www.cakephp.org', true)); - $this->assertTrue(Validation::url('http://www.cakephp.org', true)); - $this->assertTrue(Validation::url('http://example.com/~userdir/')); - $this->assertTrue(Validation::url('http://underscore_subdomain.example.org')); - $this->assertTrue(Validation::url('http://_jabber._tcp.gmail.com')); $this->assertFalse(Validation::url('http://www.underscore_domain.org')); $this->assertFalse(Validation::url('http://_jabber._tcp.g_mail.com')); + $this->assertFalse(Validation::url('http://en.(wikipedia).org/')); + $this->assertFalse(Validation::url('http://www.domain.com/fakeenco%ode')); + $this->assertFalse(Validation::url('www.cakephp.org', true)); $this->assertTrue(Validation::url('http://example.com/~userdir/subdir/index.html')); $this->assertTrue(Validation::url('http://www.zwischenraume.de')); From 393849a9bac3bae94cc91be73e1cb8df7e9d9276 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 27 Sep 2012 21:38:20 -0400 Subject: [PATCH 3/5] Make exception rendererer more resiliant Exceptions in beforeRender() should render correct error pages. Fixes #3235 --- lib/Cake/Error/ExceptionRenderer.php | 4 +- .../Test/Case/Error/ExceptionRendererTest.php | 57 +++++++++++++------ 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/lib/Cake/Error/ExceptionRenderer.php b/lib/Cake/Error/ExceptionRenderer.php index 8c69e4d0e..a404d3be8 100644 --- a/lib/Cake/Error/ExceptionRenderer.php +++ b/lib/Cake/Error/ExceptionRenderer.php @@ -290,11 +290,11 @@ class ExceptionRenderer { $this->controller->layoutPath = null; $this->controller->subDir = null; $this->controller->viewPath = 'Errors/'; - $this->controller->viewClass = 'View'; $this->controller->layout = 'error'; $this->controller->helpers = array('Form', 'Html', 'Session'); - $this->controller->render($template); + $view = new View($this->controller); + $this->controller->response->body($view->render($template, 'error')); $this->controller->response->type('html'); $this->controller->response->send(); } diff --git a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php index 46745e89e..a5704433b 100644 --- a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php +++ b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php @@ -670,25 +670,49 @@ class ExceptionRendererTest extends CakeTestCase { $exception = new MissingHelperException(array('class' => 'Fail')); $ExceptionRenderer = new ExceptionRenderer($exception); - $ExceptionRenderer->controller = $this->getMock('Controller'); + $ExceptionRenderer->controller = $this->getMock('Controller', array('render')); $ExceptionRenderer->controller->helpers = array('Fail', 'Boom'); $ExceptionRenderer->controller->request = $this->getMock('CakeRequest'); - $ExceptionRenderer->controller->expects($this->at(2)) + $ExceptionRenderer->controller->expects($this->at(0)) ->method('render') ->with('missingHelper') ->will($this->throwException($exception)); - $ExceptionRenderer->controller->expects($this->at(4)) - ->method('render') - ->with('error500') - ->will($this->returnValue(true)); + $response = $this->getMock('CakeResponse'); + $response->expects($this->once()) + ->method('body') + ->with($this->stringContains('Helper class Fail')); - $ExceptionRenderer->controller->response = $this->getMock('CakeResponse'); + $ExceptionRenderer->controller->response = $response; $ExceptionRenderer->render(); sort($ExceptionRenderer->controller->helpers); $this->assertEquals(array('Form', 'Html', 'Session'), $ExceptionRenderer->controller->helpers); } +/** + * Test that exceptions in beforeRender() are handled by outputMessageSafe + * + * @return void + */ + public function testRenderExceptionInBeforeRender() { + $exception = new NotFoundException('Not there, sorry'); + $ExceptionRenderer = new ExceptionRenderer($exception); + + $ExceptionRenderer->controller = $this->getMock('Controller', array('beforeRender')); + $ExceptionRenderer->controller->request = $this->getMock('CakeRequest'); + $ExceptionRenderer->controller->expects($this->any()) + ->method('beforeRender') + ->will($this->throwException($exception)); + + $response = $this->getMock('CakeResponse'); + $response->expects($this->once()) + ->method('body') + ->with($this->stringContains('Not there, sorry')); + + $ExceptionRenderer->controller->response = $response; + $ExceptionRenderer->render(); + } + /** * Test that missing subDir/layoutPath don't cause other fatal errors. * @@ -698,32 +722,31 @@ class ExceptionRendererTest extends CakeTestCase { $exception = new NotFoundException(); $ExceptionRenderer = new ExceptionRenderer($exception); - $ExceptionRenderer->controller = $this->getMock('Controller'); + $ExceptionRenderer->controller = $this->getMock('Controller', array('render')); $ExceptionRenderer->controller->helpers = array('Fail', 'Boom'); $ExceptionRenderer->controller->layoutPath = 'json'; $ExceptionRenderer->controller->subDir = 'json'; $ExceptionRenderer->controller->viewClass = 'Json'; $ExceptionRenderer->controller->request = $this->getMock('CakeRequest'); - $ExceptionRenderer->controller->expects($this->at(1)) + $ExceptionRenderer->controller->expects($this->once()) ->method('render') ->with('error400') ->will($this->throwException($exception)); - $ExceptionRenderer->controller->expects($this->at(3)) - ->method('render') - ->with('error500') - ->will($this->returnValue(true)); - - $ExceptionRenderer->controller->response = $this->getMock('CakeResponse'); - $ExceptionRenderer->controller->response->expects($this->once()) + $response = $this->getMock('CakeResponse'); + $response->expects($this->once()) + ->method('body') + ->with($this->stringContains('Not Found')); + $response->expects($this->once()) ->method('type') ->with('html'); + $ExceptionRenderer->controller->response = $response; + $ExceptionRenderer->render(); $this->assertEquals('', $ExceptionRenderer->controller->layoutPath); $this->assertEquals('', $ExceptionRenderer->controller->subDir); - $this->assertEquals('View', $ExceptionRenderer->controller->viewClass); $this->assertEquals('Errors/', $ExceptionRenderer->controller->viewPath); } From 2d46fc60bef5d2f11bb745c0d2f8078ee99344f8 Mon Sep 17 00:00:00 2001 From: James Michael DuPont Date: Fri, 28 Sep 2012 06:57:31 +0200 Subject: [PATCH 4/5] Fixing undefined variable usage Squash of pull request #872 --- lib/Cake/Cache/Engine/WincacheEngine.php | 1 + lib/Cake/Console/ShellDispatcher.php | 3 ++- lib/Cake/Model/Model.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Cache/Engine/WincacheEngine.php b/lib/Cake/Cache/Engine/WincacheEngine.php index 542172c0c..8e81312ab 100644 --- a/lib/Cake/Cache/Engine/WincacheEngine.php +++ b/lib/Cake/Cache/Engine/WincacheEngine.php @@ -183,6 +183,7 @@ class WincacheEngine extends CacheEngine { * @return boolean success **/ public function clearGroup($group) { + $success = null; wincache_ucache_inc($this->settings['prefix'] . $group, 1, $success); return $success; } diff --git a/lib/Cake/Console/ShellDispatcher.php b/lib/Cake/Console/ShellDispatcher.php index 6eb0e1624..162e8f508 100644 --- a/lib/Cake/Console/ShellDispatcher.php +++ b/lib/Cake/Console/ShellDispatcher.php @@ -215,7 +215,8 @@ class ShellDispatcher { return $Shell->main(); } } - throw new MissingShellMethodException(array('shell' => $shell, 'method' => $arg)); + + throw new MissingShellMethodException(array('shell' => $shell, 'method' => $command)); } /** diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 1e6dc56a5..b597ae297 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -3250,7 +3250,7 @@ class Model extends Object implements CakeEventListener { return array($with, array_unique(array_merge($assoc[$with], $keys))); } trigger_error( - __d('cake_dev', 'Invalid join model settings in %s', $model->alias), + __d('cake_dev', 'Invalid join model settings in %s. The association parameter has the wrong type, expecting a string or array, but was passed type: %s', $this->alias, gettype($assoc)), E_USER_WARNING ); } From 853d866c3567da6a832f4617d07ef3796110af01 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 28 Sep 2012 21:20:14 -0400 Subject: [PATCH 5/5] Remove port numbers from Message-id domains. Fixes #3244 --- lib/Cake/Network/Email/CakeEmail.php | 2 +- lib/Cake/Test/Case/Network/Email/CakeEmailTest.php | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index 9e5ed09b8..b812dac97 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -325,7 +325,7 @@ class CakeEmail { if ($this->_appCharset !== null) { $this->charset = $this->_appCharset; } - $this->_domain = env('HTTP_HOST'); + $this->_domain = preg_replace('/\:\d+$/', '', env('HTTP_HOST')); if (empty($this->_domain)) { $this->_domain = php_uname('n'); } diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index 94b5f373f..27e593f66 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -411,14 +411,18 @@ class CakeEmailTest extends CakeTestCase { * @return void */ public function testMessageIdWithDomain() { - $result = $this->CakeEmail->getHeaders(); - $expected = '@' . (env('HTTP_HOST') ? env('HTTP_HOST') : php_uname('n')) . '>'; - $this->assertTextContains($expected, $result['Message-ID']); - $this->CakeEmail->domain('example.org'); $result = $this->CakeEmail->getHeaders(); $expected = '@example.org>'; $this->assertTextContains($expected, $result['Message-ID']); + + $_SERVER['HTTP_HOST'] = 'example.org'; + $result = $this->CakeEmail->getHeaders(); + $this->assertTextContains('example.org', $result['Message-ID']); + + $_SERVER['HTTP_HOST'] = 'example.org:81'; + $result = $this->CakeEmail->getHeaders(); + $this->assertTextNotContains(':81', $result['Message-ID']); } /**