From 1810274c8a1f080d878d948b126116549346b9ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Rish=C3=B8j?= Date: Thu, 14 Sep 2017 11:42:34 +0700 Subject: [PATCH 1/4] escape HTML entities in `src`-attribute --- src/HtmlBuilder.php | 2 +- tests/HtmlBuilderTest.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/HtmlBuilder.php b/src/HtmlBuilder.php index d2ba3cd..fa6f319 100755 --- a/src/HtmlBuilder.php +++ b/src/HtmlBuilder.php @@ -162,7 +162,7 @@ class HtmlBuilder $title = $this->entities($title); } - return $this->toHtmlString('attributes($attributes) . '>' . $title . ''); + return $this->toHtmlString('attributes($attributes) . '>' . $title . ''); } /** diff --git a/tests/HtmlBuilderTest.php b/tests/HtmlBuilderTest.php index b5d7d99..9a4d486 100644 --- a/tests/HtmlBuilderTest.php +++ b/tests/HtmlBuilderTest.php @@ -118,8 +118,11 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase $result2 = $this->htmlBuilder->link("http://www.example.com", "Example.com", ["class" => "example-link"], null, false); + $result3 = $this->htmlBuilder->link("https://a.com/b?id=4¬_id=5", "URL which needs escaping"); + $this->assertEquals('<span>Example.com</span>', $result1); $this->assertEquals('Example.com', $result2); + $this->assertEquals('URL which needs escaping', $result3); } public function testMailto() From cecb65626c33e89d9f8545d3119b5b7d0119b96f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Bayer=20Soler?= Date: Mon, 5 Feb 2018 15:04:30 +0100 Subject: [PATCH 2/4] Nested optgroups (#470) * fix optionGroup and added a function to handle recursively the arrays * simplify recursively * fix codestyle * fix codestyle * add new parameter annotation --- src/FormBuilder.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index a0cb439..dd2753a 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -699,20 +699,23 @@ class FormBuilder * @param string $selected * @param array $attributes * @param array $optionsAttributes + * @param integer $level * * @return \Illuminate\Support\HtmlString */ - protected function optionGroup($list, $label, $selected, array $attributes = [], array $optionsAttributes = []) + protected function optionGroup($list, $label, $selected, array $attributes = [], array $optionsAttributes = [], $level = 0) { $html = []; - + $space = str_repeat(" ", $level); foreach ($list as $value => $display) { $optionAttributes = $optionsAttributes[$value] ?? []; - - $html[] = $this->option($display, $value, $selected, $optionAttributes); + if (is_array($display)) { + $html[] = $this->optionGroup($display, $value, $selected, $attributes, $optionAttributes, $level+5); + } else { + $html[] = $this->option($space.$display, $value, $selected, $attributes, $optionAttributes); + } } - - return $this->toHtmlString('html->attributes($attributes) . '>' . implode('', $html) . ''); + return $this->toHtmlString('' . implode('', $html) . ''); } /** From e1318fcfdd1c713b7198557f1a62d33eb1da559b Mon Sep 17 00:00:00 2001 From: Vendin Date: Mon, 5 Feb 2018 17:58:09 +0300 Subject: [PATCH 3/4] Getting data for a form from a relation (#472) --- src/Eloquent/FormAccessible.php | 4 ++-- tests/FormAccessibleTest.php | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Eloquent/FormAccessible.php b/src/Eloquent/FormAccessible.php index 9b5d6d0..eb74013 100644 --- a/src/Eloquent/FormAccessible.php +++ b/src/Eloquent/FormAccessible.php @@ -49,7 +49,7 @@ trait FormAccessible unset($keys[0]); $key = implode('.', $keys); - if ($this->hasFormMutator($key)) { + if (method_exists($relatedModel, 'hasFormMutator') && $relatedModel->hasFormMutator($key)) { return $relatedModel->getFormValue($key); } @@ -81,7 +81,7 @@ trait FormAccessible * * @return bool */ - protected function hasFormMutator($key) + public function hasFormMutator($key) { $methods = $this->getReflection()->getMethods(ReflectionMethod::IS_PUBLIC); diff --git a/tests/FormAccessibleTest.php b/tests/FormAccessibleTest.php index 9f25686..2a1ef46 100644 --- a/tests/FormAccessibleTest.php +++ b/tests/FormAccessibleTest.php @@ -42,10 +42,13 @@ class FormAccessibleTest extends PHPUnit_Framework_TestCase public function testItCanMutateValuesForForms() { $model = new ModelThatUsesForms($this->modelData); + $user = new User(['name' => 'Anton']); + $model->setRelation('user', $user); $this->formBuilder->setModel($model); $this->assertEquals($model->getFormValue('string'), 'ponmlkjihgfedcba'); $this->assertEquals($model->getFormValue('created_at'), $this->now->timestamp); + $this->assertEquals('Get name for form: Anton', $model->getFormValue('user.name')); } public function testItCanMutateRelatedValuesForForms() @@ -159,3 +162,13 @@ class ModelThatDoesntUseForms extends Model return '1 second ago'; } } + +class User extends Model +{ + use FormAccessible; + + public function formNameAttribute($value) + { + return 'Get name for form: ' . $value; + } +} From 5feb06537d3bbbe9cdd19ffda892d46c749cf836 Mon Sep 17 00:00:00 2001 From: ThunderbirdsX3 Date: Mon, 5 Feb 2018 21:59:23 +0700 Subject: [PATCH 4/4] Fix placeholder not hide in select list. (#473) * Update test. * Fix place holder show in select list. --- src/FormBuilder.php | 2 +- tests/FormBuilderTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index dd2753a..d35813e 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -759,7 +759,7 @@ class FormBuilder 'value' => '', ]; - return $this->toHtmlString('html->attributes($options) . '>' . e($display) . ''); + return $this->toHtmlString('html->attributes($options) . ' hidden="hidden">' . e($display) . ''); } /** diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index e6b1765..47ff1b9 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -510,7 +510,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase ['placeholder' => 'Select One...'] ); $this->assertEquals($select, - ''); + ''); $select = $this->formBuilder->select( 'size', @@ -519,7 +519,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase ['placeholder' => 'Select One...'] ); $this->assertEquals($select, - ''); + ''); $select = $this->formBuilder->select( 'encoded_html', @@ -528,7 +528,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase ['placeholder' => 'Select the  '] ); $this->assertEquals($select, - '' + '' ); }