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
+40 -15

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.
$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);
}
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];
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['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>');
}
/**
+3 -3
View File
@@ -288,7 +288,7 @@ class HtmlBuilder
{
return str_repeat('&nbsp;', $num);
}
/**
* Generate an ordered list of items.
*
@@ -387,7 +387,7 @@ class HtmlBuilder
if (is_array($value)) {
return $this->nestedListing($key, $type, $value);
} 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)) {
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');
$form2 = $this->formBuilder->textarea('foo', 'foobar');
$form3 = $this->formBuilder->textarea('foo', null, ['class' => 'span2']);
$form4 = $this->formBuilder->textarea('foo', null, ['size' => '60x15']);
$form3 = $this->formBuilder->textarea('foo', '&amp;');
$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">foobar</textarea>', $form2);
$this->assertEquals('<textarea class="span2" name="foo" cols="50" rows="10"></textarea>', $form3);
$this->assertEquals('<textarea name="foo" cols="60" rows="15"></textarea>', $form4);
$this->assertEquals('<textarea name="foo" cols="50" rows="10">&amp;amp;</textarea>', $form3);
$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()
@@ -287,6 +289,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
'Large sizes' => [
'L' => 'Large',
'XL' => 'Extra Large',
'XXL' => 'Extra&nbsp;Large',
],
'S' => 'Small',
],
@@ -299,7 +302,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
$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',
['L' => 'Large', 'S' => 'Small'],
null,
['placeholder' => 'Select One...']
['placeholder' => 'Select &nbsp;One...']
);
$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(
'size',
+23 -1
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);
}
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()
{
$result = $this->htmlBuilder->meta('description', 'Lorem ipsum dolor sit amet.');
@@ -58,7 +80,7 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase
$this->htmlBuilder->image('http://example.com/image1'),
$this->htmlBuilder->image('http://example.com/image2'),
];
$result4 = $this->htmlBuilder->tag('div', $content, ['class' => 'row']);
$this->assertEquals('<p>' . PHP_EOL . 'Lorem ipsum dolor sit amet.' . PHP_EOL . '</p>' . PHP_EOL, $result1);