Values are encoded consistently by the formbuilder and the htmlbuilder

This commit is contained in:
Stefan Printezis committed 2016-10-28 12:37:15 +02:00
1 parent abec449ed8
commit c1a105975b
4 files changed
+38 -13

No files matched your search

+4 -4
View File
@@ -485,7 +485,7 @@ class FormBuilder
// the element. Then we'll create the final textarea elements HTML for us. // the element. Then we'll create the final textarea elements HTML for us.
$options = $this->html->attributes($options); $options = $this->html->attributes($options);
return $this->toHtmlString('<textarea' . $options . '>' . e($value) . '</textarea>'); return $this->toHtmlString('<textarea' . $options . '>' . htmlentities($value, ENT_QUOTES, 'UTF-8') . '</textarea>');
} }
/** /**
@@ -662,7 +662,7 @@ class FormBuilder
$html[] = $this->option($display, $value, $selected); $html[] = $this->option($display, $value, $selected);
} }
return $this->toHtmlString('<optgroup label="' . e($label) . '">' . implode('', $html) . '</optgroup>'); return $this->toHtmlString('<optgroup label="' . htmlentities($label, ENT_QUOTES, 'UTF-8') . '">' . implode('', $html) . '</optgroup>');
} }
/** /**
@@ -680,7 +680,7 @@ class FormBuilder
$options = ['value' => $value, 'selected' => $selected]; $options = ['value' => $value, 'selected' => $selected];
return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . e($display) . '</option>'); return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . htmlentities($display, ENT_QUOTES, 'UTF-8') . '</option>');
} }
/** /**
@@ -698,7 +698,7 @@ class FormBuilder
$options = compact('selected'); $options = compact('selected');
$options['value'] = ''; $options['value'] = '';
return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . e($display) . '</option>'); return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . htmlentities($display, ENT_QUOTES, 'UTF-8') . '</option>');
} }
/** /**
+2 -2
View File
@@ -387,7 +387,7 @@ class HtmlBuilder
if (is_array($value)) { if (is_array($value)) {
return $this->nestedListing($key, $type, $value); return $this->nestedListing($key, $type, $value);
} else { } else {
return '<li>' . e($value) . '</li>'; return '<li>' . htmlentities($value, ENT_QUOTES, 'UTF-8') . '</li>';
} }
} }
@@ -449,7 +449,7 @@ class HtmlBuilder
} }
if (! is_null($value)) { if (! is_null($value)) {
return $key . '="' . e($value) . '"'; return $key . '="' . htmlentities($value, ENT_QUOTES, 'UTF-8') . '"';
} }
} }
+10 -7
View File
@@ -237,13 +237,15 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
{ {
$form1 = $this->formBuilder->textarea('foo'); $form1 = $this->formBuilder->textarea('foo');
$form2 = $this->formBuilder->textarea('foo', 'foobar'); $form2 = $this->formBuilder->textarea('foo', 'foobar');
$form3 = $this->formBuilder->textarea('foo', null, ['class' => 'span2']); $form3 = $this->formBuilder->textarea('foo', '&amp;');
$form4 = $this->formBuilder->textarea('foo', null, ['size' => '60x15']); $form4 = $this->formBuilder->textarea('foo', null, ['class' => 'span2']);
$form5 = $this->formBuilder->textarea('foo', null, ['size' => '60x15']);
$this->assertEquals('<textarea name="foo" cols="50" rows="10"></textarea>', $form1); $this->assertEquals('<textarea name="foo" cols="50" rows="10"></textarea>', $form1);
$this->assertEquals('<textarea name="foo" cols="50" rows="10">foobar</textarea>', $form2); $this->assertEquals('<textarea name="foo" cols="50" rows="10">foobar</textarea>', $form2);
$this->assertEquals('<textarea class="span2" name="foo" cols="50" rows="10"></textarea>', $form3); $this->assertEquals('<textarea name="foo" cols="50" rows="10">&amp;amp;</textarea>', $form3);
$this->assertEquals('<textarea name="foo" cols="60" rows="15"></textarea>', $form4); $this->assertEquals('<textarea class="span2" name="foo" cols="50" rows="10"></textarea>', $form4);
$this->assertEquals('<textarea name="foo" cols="60" rows="15"></textarea>', $form5);
} }
public function testSelect() public function testSelect()
@@ -287,6 +289,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
'Large sizes' => [ 'Large sizes' => [
'L' => 'Large', 'L' => 'Large',
'XL' => 'Extra Large', 'XL' => 'Extra Large',
'XXL' => 'Extra&nbsp;Large',
], ],
'S' => 'Small', 'S' => 'Small',
], ],
@@ -299,7 +302,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
$this->assertEquals( $this->assertEquals(
$select, $select,
'<select class="class-name" id="select-id" name="size"><optgroup label="Large sizes"><option value="L">Large</option><option value="XL">Extra Large</option></optgroup><option value="S">Small</option></select>' '<select class="class-name" id="select-id" name="size"><optgroup label="Large sizes"><option value="L">Large</option><option value="XL">Extra Large</option><option value="XXL">Extra&amp;nbsp;Large</option></optgroup><option value="S">Small</option></select>'
); );
} }
@@ -331,10 +334,10 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
'size', 'size',
['L' => 'Large', 'S' => 'Small'], ['L' => 'Large', 'S' => 'Small'],
null, null,
['placeholder' => 'Select One...'] ['placeholder' => 'Select &nbsp;One...']
); );
$this->assertEquals($select, $this->assertEquals($select,
'<select name="size"><option selected="selected" value="">Select One...</option><option value="L">Large</option><option value="S">Small</option></select>'); '<select name="size"><option selected="selected" value="">Select &amp;nbsp;One...</option><option value="L">Large</option><option value="S">Small</option></select>');
$select = $this->formBuilder->select( $select = $this->formBuilder->select(
'size', 'size',
+22
View File
@@ -39,6 +39,28 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase
$this->assertEquals('<dl class="example"><dt>foo</dt><dd>bar</dd><dt>bing</dt><dd>baz</dd></dl>', $result); $this->assertEquals('<dl class="example"><dt>foo</dt><dd>bar</dd><dt>bing</dt><dd>baz</dd></dl>', $result);
} }
public function testOl()
{
$list = ['foo', 'bar', '&amp;'];
$attributes = ['class' => 'example'];
$ol = $this->htmlBuilder->ol($list, $attributes);
$this->assertEquals('<ol class="example"><li>foo</li><li>bar</li><li>&amp;amp;</li></ol>', $ol);
}
public function testUl()
{
$list = ['foo', 'bar', '&amp;'];
$attributes = ['class' => 'example'];
$ul = $this->htmlBuilder->ul($list, $attributes);
$this->assertEquals('<ul class="example"><li>foo</li><li>bar</li><li>&amp;amp;</li></ul>', $ul);
}
public function testMeta() public function testMeta()
{ {
$result = $this->htmlBuilder->meta('description', 'Lorem ipsum dolor sit amet.'); $result = $this->htmlBuilder->meta('description', 'Lorem ipsum dolor sit amet.');