Compare commits

..
14 Commits
8 changed files with 90 additions and 49 deletions

No files matched your search

+1 -1
View File
@@ -1,9 +1,9 @@
language: php
php:
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm
sudo: false
+9 -9
View File
@@ -18,17 +18,17 @@
}
],
"require": {
"php": ">=5.5.9",
"illuminate/http": "5.2.*",
"illuminate/routing": "5.2.*",
"illuminate/session": "5.2.*",
"illuminate/support": "5.2.*",
"illuminate/view": "5.2.*"
"php": ">=5.6.4",
"illuminate/http": "5.4.*",
"illuminate/routing": "5.4.*",
"illuminate/session": "5.4.*",
"illuminate/support": "5.4.*",
"illuminate/view": "5.4.*"
},
"require-dev": {
"illuminate/database": "5.2.*",
"mockery/mockery": "~0.9",
"phpunit/phpunit": "~4.0"
"illuminate/database": "5.4.*",
"mockery/mockery": "~0.9.4",
"phpunit/phpunit": "~5.4"
},
"autoload": {
"psr-4": {
+1 -1
View File
@@ -55,7 +55,7 @@ trait FormAccessible
$methods = $this->getReflection()->getMethods(ReflectionMethod::IS_PUBLIC);
$mutator = collect($methods)
->first(function ($index, ReflectionMethod $method) use ($key) {
->first(function (ReflectionMethod $method) use ($key) {
return $method->getName() == 'form' . Str::studly($key) . 'Attribute';
});
+10 -10
View File
@@ -7,7 +7,7 @@ use BadMethodCallException;
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
use Illuminate\Contracts\View\Factory;
use Illuminate\Session\SessionInterface;
use Illuminate\Contracts\Session\Session;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Routing\UrlGenerator;
@@ -49,7 +49,7 @@ class FormBuilder
/**
* The session store implementation.
*
* @var \Illuminate\Session\SessionInterface
* @var \Illuminate\Contracts\Session\Session
*/
protected $session;
@@ -198,7 +198,7 @@ class FormBuilder
*/
public function token()
{
$token = ! empty($this->csrfToken) ? $this->csrfToken : $this->session->getToken();
$token = ! empty($this->csrfToken) ? $this->csrfToken : $this->session->token();
return $this->hidden('_token', $token);
}
@@ -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 . '>' . $this->html->escapeAll($value). '</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="' . $this->html->escapeAll($label) . '">' . 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) . '>' . $this->html->escapeAll($display) . '</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) . '>' . $this->html->escapeAll($display) . '</option>');
}
/**
@@ -1164,7 +1164,7 @@ class FormBuilder
/**
* Get the session store implementation.
*
* @return \Illuminate\Session\SessionInterface $session
* @return \Illuminate\Contracts\Session\Session $session
*/
public function getSessionStore()
{
@@ -1174,11 +1174,11 @@ class FormBuilder
/**
* Set the session store implementation.
*
* @param \Illuminate\Session\SessionInterface $session
* @param \Illuminate\Contracts\Session\Session $session
*
* @return $this
*/
public function setSessionStore(SessionInterface $session)
public function setSessionStore(Session $session)
{
$this->session = $session;
+15 -8
View File
@@ -53,6 +53,18 @@ 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.
*
@@ -288,7 +300,7 @@ class HtmlBuilder
{
return str_repeat('&nbsp;', $num);
}
/**
* Generate an ordered list of items.
*
@@ -387,7 +399,7 @@ class HtmlBuilder
if (is_array($value)) {
return $this->nestedListing($key, $type, $value);
} else {
return '<li>' . e($value) . '</li>';
return '<li>' . $this->escapeAll($value) . '</li>';
}
}
@@ -447,14 +459,9 @@ class HtmlBuilder
if (is_numeric($key)) {
$key = $value;
}
// Treat boolean attributes as HTML properties
if (is_bool($value)) {
return $value ? $key : '';
}
if (! is_null($value)) {
return $key . '="' . e($value) . '"';
return $key . '="' . $this->escapeAll($value) . '"';
}
}
+1 -1
View File
@@ -49,7 +49,7 @@ class HtmlServiceProvider extends ServiceProvider
protected function registerFormBuilder()
{
$this->app->singleton('form', function ($app) {
$form = new FormBuilder($app['html'], $app['url'], $app['view'], $app['session.store']->getToken());
$form = new FormBuilder($app['html'], $app['url'], $app['view'], $app['session.store']->token());
return $form->setSessionStore($app['session.store']);
});
+31 -8
View File
@@ -78,7 +78,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
public function testPasswordsNotFilled()
{
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Contracts\Session\Session'));
$session->shouldReceive('getOldInput')->never();
@@ -89,7 +89,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
public function testFilesNotFilled()
{
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Contracts\Session\Session'));
$session->shouldReceive('getOldInput')->never();
@@ -113,7 +113,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
public function testFormTextRepopulation()
{
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Contracts\Session\Session'));
$this->setModel($model = ['relation' => ['key' => 'attribute'], 'other' => 'val']);
$session->shouldReceive('getOldInput')->twice()->with('name_with_dots')->andReturn('some value');
@@ -239,11 +239,13 @@ 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', '&amp;');
$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="encoded_html" cols="50" rows="10">&amp;amp;</textarea>', $form5);
}
public function testSelect()
@@ -301,12 +303,23 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
$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 = $this->formBuilder->select(
'encoded_html',
['no_break_space' => '&nbsp;', 'ampersand' => '&amp;', 'lower_than' => '&lt;'],
null
);
$this->assertEquals(
$select,
'<select name="encoded_html"><option value="no_break_space">&amp;nbsp;</option><option value="ampersand">&amp;amp;</option><option value="lower_than">&amp;lt;</option></select>'
);
}
public function testFormSelectRepopulation()
{
$list = ['L' => 'Large', 'M' => 'Medium', 'S' => 'Small'];
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Contracts\Session\Session'));
$this->setModel($model = ['size' => ['key' => 'S'], 'other' => 'val']);
$session->shouldReceive('getOldInput')->twice()->with('size')->andReturn('M');
@@ -344,6 +357,16 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
);
$this->assertEquals($select,
'<select name="size"><option value="">Select One...</option><option value="L" selected="selected">Large</option><option value="S">Small</option></select>');
$select = $this->formBuilder->select(
'encoded_html',
['no_break_space' => '&nbsp;', 'ampersand' => '&amp;', 'lower_than' => '&lt;'],
null,
['placeholder' => 'Select the &nbsp;']
);
$this->assertEquals($select,
'<select name="encoded_html"><option selected="selected" value="">Select the &amp;nbsp;</option><option value="no_break_space">&amp;nbsp;</option><option value="ampersand">&amp;amp;</option><option value="lower_than">&amp;lt;</option></select>'
);
}
public function testFormSelectYear()
@@ -382,7 +405,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
public function testFormCheckbox()
{
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Contracts\Session\Session'));
$session->shouldReceive('getOldInput')->withNoArgs()->andReturn([]);
$session->shouldReceive('getOldInput')->with('foo')->andReturn(null);
@@ -400,7 +423,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
public function testFormCheckboxRepopulation()
{
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Contracts\Session\Session'));
$session->shouldReceive('getOldInput')->withNoArgs()->andReturn([1]);
$session->shouldReceive('getOldInput')->once()->with('check')->andReturn(null);
@@ -423,7 +446,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
public function testFormCheckboxWithModelRelation()
{
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Contracts\Session\Session'));
$session->shouldReceive('getOldInput')->withNoArgs()->andReturn([]);
$session->shouldReceive('getOldInput')->with('items')->andReturn(null);
@@ -468,7 +491,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
public function testFormRadioRepopulation()
{
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Contracts\Session\Session'));
$session->shouldReceive('getOldInput')->with('radio')->andReturn(1);
+22 -11
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.');
@@ -115,15 +137,4 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase
$this->assertEquals('<a href="mailto:person@example.com" class="example-link">&lt;span&gt;First Name Last&lt;/span&gt;</a>', $result1);
$this->assertEquals('<a href="mailto:person@example.com" class="example-link"><span>First Name Last</span></a>', $result2);
}
public function testBooleanAttributes()
{
$result1 = $this->htmlBuilder->attributes(['my-property' => true]);
$result2 = $this->htmlBuilder->attributes(['my-property' => false]);
$this->assertEquals('my-property', trim($result1));
$this->assertEquals('', trim($result2));
}
}