From 9e15042eff6e1af214dd895537a5ae6dc098f829 Mon Sep 17 00:00:00 2001 From: samokspv Date: Thu, 13 Mar 2014 19:11:14 +0200 Subject: [PATCH 1/4] changed regexp for response code Facebook servers have now HTTP response without status string. The use "HTTP/1.1 200 " while CakePHP needs "HTTP/1.1 200 Ok" because preg_match() in code use + instead * --- lib/Cake/Network/Http/HttpSocketResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Network/Http/HttpSocketResponse.php b/lib/Cake/Network/Http/HttpSocketResponse.php index 8be475c01..9b0265dac 100644 --- a/lib/Cake/Network/Http/HttpSocketResponse.php +++ b/lib/Cake/Network/Http/HttpSocketResponse.php @@ -159,7 +159,7 @@ class HttpSocketResponse implements ArrayAccess { $this->raw = $message; $this->body = (string)substr($message, strlen($match[0])); - if (preg_match("/(.+) ([0-9]{3}) (.+)\r\n/DU", $statusLine, $match)) { + if (preg_match("/(.+) ([0-9]{3}) (.*)\r\n/DU", $statusLine, $match)) { $this->httpVersion = $match[1]; $this->code = $match[2]; $this->reasonPhrase = $match[3]; From 9888209e9aadb01b90eaf422df93d685c3535949 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 17 Mar 2014 13:08:46 -0400 Subject: [PATCH 2/4] Add tests and fix issues with multiple trailing whitespaces. Closes #3016 --- lib/Cake/Network/Http/HttpSocketResponse.php | 2 +- .../Test/Case/Network/Http/HttpSocketTest.php | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Network/Http/HttpSocketResponse.php b/lib/Cake/Network/Http/HttpSocketResponse.php index 9b0265dac..b20e0643b 100644 --- a/lib/Cake/Network/Http/HttpSocketResponse.php +++ b/lib/Cake/Network/Http/HttpSocketResponse.php @@ -159,7 +159,7 @@ class HttpSocketResponse implements ArrayAccess { $this->raw = $message; $this->body = (string)substr($message, strlen($match[0])); - if (preg_match("/(.+) ([0-9]{3}) (.*)\r\n/DU", $statusLine, $match)) { + if (preg_match("/(.+) ([0-9]{3})\s*([^ ]*)\r\n/DU", $statusLine, $match)) { $this->httpVersion = $match[1]; $this->code = $match[2]; $this->reasonPhrase = $match[3]; diff --git a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php b/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php index c2fcd1a22..8f3c46079 100644 --- a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php +++ b/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php @@ -1754,4 +1754,41 @@ class HttpSocketTest extends CakeTestCase { $this->assertContains('Failed to enable crypto', $message); } } + +/** + * Data provider for status codes. + * + * @return array + */ + public function statusProvider() { + return array( + array('HTTP/1.1 200 '), + array('HTTP/1.1 200 '), + array('HTTP/1.1 200'), + array('HTTP/1.1 200 OK', 'OK'), + ); + } + +/** + * test response status parsing + * + * @dataProvider statusProvider + * @return void + */ + public function testResponseStatusParsing($status, $msg = '') { + $this->Socket->connected = true; + $serverResponse = $status . "\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\n\r\n

This is a test!

"; + $this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); + $this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false)); + + $response = $this->Socket->request('http://www.cakephp.org/'); + $this->assertInstanceOf('HttpSocketResponse', $response); + $expected = array( + 'http-version' => 'HTTP/1.1', + 'code' => '200', + 'reason-phrase' => $msg + ); + $this->assertEquals($expected, $response['status']); + } + } From d55a1678300a5eb7d8babf7f35e39d6f9b0302c6 Mon Sep 17 00:00:00 2001 From: Hadrien Date: Tue, 18 Mar 2014 14:22:24 +0100 Subject: [PATCH 3/4] Themed CakeEmail should load view helpers with the theme set --- lib/Cake/Network/Email/CakeEmail.php | 9 ++++++--- lib/Cake/Test/Case/Network/Email/CakeEmailTest.php | 1 + .../View/Themed/TestTheme/Emails/text/themed.ctp | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index 257ed3c91..f0cd00f30 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1623,6 +1623,11 @@ class CakeEmail { $View = new $viewClass(null); $View->viewVars = $this->_viewVars; $View->helpers = $this->_helpers; + + if ($this->_theme) { + $View->theme = $this->_theme; + } + $View->loadHelpers(); list($templatePlugin, $template) = pluginSplit($this->_template); @@ -1632,9 +1637,7 @@ class CakeEmail { } elseif ($layoutPlugin) { $View->plugin = $layoutPlugin; } - if ($this->_theme) { - $View->theme = $this->_theme; - } + // Convert null to false, as View needs false to disable // the layout. if ($layout === null) { diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index 83db092db..2279b324d 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -1337,6 +1337,7 @@ class CakeEmailTest extends CakeTestCase { $this->assertContains('In TestTheme', $result['message']); $this->assertContains('Message-ID: ', $result['headers']); $this->assertContains('To: ', $result['headers']); + $this->assertContains('/theme/TestTheme/img/test.jpg', $result['message']); } /** diff --git a/lib/Cake/Test/test_app/View/Themed/TestTheme/Emails/text/themed.ctp b/lib/Cake/Test/test_app/View/Themed/TestTheme/Emails/text/themed.ctp index 5ea24fbc7..f49115333 100644 --- a/lib/Cake/Test/test_app/View/Themed/TestTheme/Emails/text/themed.ctp +++ b/lib/Cake/Test/test_app/View/Themed/TestTheme/Emails/text/themed.ctp @@ -1 +1,2 @@ In TestTheme +Html->image('test.jpg') ?> \ No newline at end of file From ee895a8bb1edeb93c548cc17e4141b453004cef2 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 18 Mar 2014 22:11:57 -0400 Subject: [PATCH 4/4] Add form attribute to hidden inputs when present. If inputs are placed outside of the form elements the form attribute needs to be set on the hidden inputs. Without this attribute the empty state does not submit correctly. Fixes #3053 --- .../Test/Case/View/Helper/FormHelperTest.php | 31 +++++++++++++------ lib/Cake/View/Helper/FormHelper.php | 9 ++++-- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 0786c6007..4a7ba4946 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -3614,18 +3614,22 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $result = $this->Form->radio('Employee.gender', array('male' => 'Male', 'female' => 'Female')); + $result = $this->Form->radio( + 'Employee.gender', + array('male' => 'Male', 'female' => 'Female'), + array('form' => 'my-form') + ); $expected = array( 'fieldset' => array(), 'legend' => array(), 'Gender', '/legend', - 'input' => array('type' => 'hidden', 'name' => 'data[Employee][gender]', 'value' => '', 'id' => 'EmployeeGender_'), - array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'male', 'id' => 'EmployeeGenderMale')), + 'input' => array('type' => 'hidden', 'name' => 'data[Employee][gender]', 'value' => '', 'id' => 'EmployeeGender_', 'form' => 'my-form'), + array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'male', 'id' => 'EmployeeGenderMale', 'form' => 'my-form')), array('label' => array('for' => 'EmployeeGenderMale')), 'Male', '/label', - array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'female', 'id' => 'EmployeeGenderFemale')), + array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'female', 'id' => 'EmployeeGenderFemale', 'form' => 'my-form')), array('label' => array('for' => 'EmployeeGenderFemale')), 'Female', '/label', @@ -4650,15 +4654,18 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); $result = $this->Form->select( - 'Model.multi_field', $options, array('multiple' => 'multiple') + 'Model.multi_field', $options, array('form' => 'my-form', 'multiple' => 'multiple') ); $expected = array( 'input' => array( - 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_' + 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_', + 'form' => 'my-form', ), 'select' => array( 'name' => 'data[Model][multi_field][]', - 'id' => 'ModelMultiField', 'multiple' => 'multiple' + 'id' => 'ModelMultiField', + 'multiple' => 'multiple', + 'form' => 'my-form', ), array('option' => array('value' => '0')), 'first', @@ -5674,10 +5681,14 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue')); + $result = $this->Form->checkbox('Model.field', array( + 'id' => 'theID', + 'value' => 'myvalue', + 'form' => 'my-form', + )); $expected = array( - 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_'), - array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => 'myvalue', 'id' => 'theID')) + 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_', 'form' => 'my-form'), + array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => 'myvalue', 'id' => 'theID', 'form' => 'my-form')) ); $this->assertTags($result, $expected); diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 4f7bf48da..4a532003b 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1418,7 +1418,8 @@ class FormHelper extends AppHelper { 'id' => $options['id'] . '_', 'name' => $options['name'], 'value' => ($options['hiddenField'] !== true ? $options['hiddenField'] : '0'), - 'secure' => false + 'form' => isset($options['form']) ? $options['form'] : null, + 'secure' => false, ); if (isset($options['disabled']) && $options['disabled']) { $hiddenOptions['disabled'] = 'disabled'; @@ -1544,7 +1545,10 @@ class FormHelper extends AppHelper { if ($hiddenField) { if (!isset($value) || $value === '') { $hidden = $this->hidden($fieldName, array( - 'id' => $attributes['id'] . '_', 'value' => '', 'name' => $attributes['name'] + 'form' => isset($attributes['form']) ? $attributes['form'] : null, + 'id' => $attributes['id'] . '_', + 'value' => '', + 'name' => $attributes['name'] )); } } @@ -2008,6 +2012,7 @@ class FormHelper extends AppHelper { 'value' => '', 'id' => $attributes['id'] . ($style ? '' : '_'), 'secure' => false, + 'form' => isset($attributes['form']) ? $attributes['form'] : null, 'name' => $attributes['name'] ); $select[] = $this->hidden(null, $hiddenAttributes);