From 856e1e6d6b8036e7371d0d8b20eab48f3d4b08c8 Mon Sep 17 00:00:00 2001 From: mlantz Date: Thu, 20 Apr 2017 00:02:24 -0400 Subject: [PATCH] Fixes for escape issue --- src/FormBuilder.php | 8 ++++---- src/HtmlBuilder.php | 16 ++-------------- tests/FormBuilderTest.php | 23 ----------------------- tests/HtmlBuilderTest.php | 22 ---------------------- 4 files changed, 6 insertions(+), 63 deletions(-) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index b10b808..28f7c69 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -485,7 +485,7 @@ class FormBuilder // the element. Then we'll create the final textarea elements HTML for us. $options = $this->html->attributes($options); - return $this->toHtmlString('' . $this->html->escapeAll($value). ''); + return $this->toHtmlString('' . e($value). ''); } /** @@ -662,7 +662,7 @@ class FormBuilder $html[] = $this->option($display, $value, $selected); } - return $this->toHtmlString('' . implode('', $html) . ''); + return $this->toHtmlString('' . implode('', $html) . ''); } /** @@ -680,7 +680,7 @@ class FormBuilder $options = ['value' => $value, 'selected' => $selected]; - return $this->toHtmlString('html->attributes($options) . '>' . $this->html->escapeAll($display) . ''); + return $this->toHtmlString('html->attributes($options) . '>' . e($display) . ''); } /** @@ -698,7 +698,7 @@ class FormBuilder $options = compact('selected'); $options['value'] = ''; - return $this->toHtmlString('html->attributes($options) . '>' . $this->html->escapeAll($display) . ''); + return $this->toHtmlString('html->attributes($options) . '>' . e($display) . ''); } /** diff --git a/src/HtmlBuilder.php b/src/HtmlBuilder.php index e6bc518..e531792 100755 --- a/src/HtmlBuilder.php +++ b/src/HtmlBuilder.php @@ -53,18 +53,6 @@ class HtmlBuilder return htmlentities($value, ENT_QUOTES, 'UTF-8', false); } - /** - * Convert all applicable characters to HTML entities. - * - * @param string $value - * - * @return string - */ - public function escapeAll($value) - { - return htmlentities($value, ENT_QUOTES, 'UTF-8'); - } - /** * Convert entities to HTML characters. * @@ -399,7 +387,7 @@ class HtmlBuilder if (is_array($value)) { return $this->nestedListing($key, $type, $value); } else { - return '
  • ' . $this->escapeAll($value) . '
  • '; + return '
  • ' . e($value) . '
  • '; } } @@ -461,7 +449,7 @@ class HtmlBuilder } if (! is_null($value)) { - return $key . '="' . $this->escapeAll($value) . '"'; + return $key . '="' . e($value) . '"'; } } diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index ff7b37e..0146c2b 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -239,13 +239,11 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase $form2 = $this->formBuilder->textarea('foo', 'foobar'); $form3 = $this->formBuilder->textarea('foo', null, ['class' => 'span2']); $form4 = $this->formBuilder->textarea('foo', null, ['size' => '60x15']); - $form5 = $this->formBuilder->textarea('encoded_html', '&'); $this->assertEquals('', $form1); $this->assertEquals('', $form2); $this->assertEquals('', $form3); $this->assertEquals('', $form4); - $this->assertEquals('', $form5); } public function testSelect() @@ -303,17 +301,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase $select, '' ); - - $select = $this->formBuilder->select( - 'encoded_html', - ['no_break_space' => ' ', 'ampersand' => '&', 'lower_than' => '<'], - null - ); - - $this->assertEquals( - $select, - '' - ); } public function testFormSelectRepopulation() @@ -357,16 +344,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase ); $this->assertEquals($select, ''); - - $select = $this->formBuilder->select( - 'encoded_html', - ['no_break_space' => ' ', 'ampersand' => '&', 'lower_than' => '<'], - null, - ['placeholder' => 'Select the  '] - ); - $this->assertEquals($select, - '' - ); } public function testFormSelectYear() diff --git a/tests/HtmlBuilderTest.php b/tests/HtmlBuilderTest.php index 747c89a..cdc0c4a 100644 --- a/tests/HtmlBuilderTest.php +++ b/tests/HtmlBuilderTest.php @@ -39,28 +39,6 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase $this->assertEquals('
    foo
    bar
    bing
    baz
    ', $result); } - public function testOl() - { - $list = ['foo', 'bar', '&']; - - $attributes = ['class' => 'example']; - - $ol = $this->htmlBuilder->ol($list, $attributes); - - $this->assertEquals('
    1. foo
    2. bar
    3. &amp;
    ', $ol); - } - - public function testUl() - { - $list = ['foo', 'bar', '&']; - - $attributes = ['class' => 'example']; - - $ul = $this->htmlBuilder->ul($list, $attributes); - - $this->assertEquals('
    • foo
    • bar
    • &amp;
    ', $ul); - } - public function testMeta() { $result = $this->htmlBuilder->meta('description', 'Lorem ipsum dolor sit amet.');