Skip to content

Commit

Permalink
Merge pull request #2 from egeloen/base64-option
Browse files Browse the repository at this point in the history
Only allow bool values for base64 option
  • Loading branch information
GeLoLabs committed May 21, 2016
2 parents 289969c + a42ef79 commit 79d36b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -7,6 +7,9 @@ php:
- 7.0
- hhvm

branches:
only: master

env:
global:
- COMPOSER_PREFER_LOWEST=false
Expand Down
6 changes: 6 additions & 0 deletions Form/Extension/Base64FileExtension.php
Expand Up @@ -52,6 +52,12 @@ public function configureOptions(OptionsResolver $resolver)
return !$options['base64'] ? $value : null;
},
]);

if (method_exists($resolver, 'setDefault')) {
$resolver->setAllowedTypes('base64', 'bool');
} else {
$resolver->setAllowedTypes(array('base64' => 'bool'));
}
}

/**
Expand Down
9 changes: 9 additions & 0 deletions Tests/Form/Extension/Base64FileExtensionTest.php
Expand Up @@ -106,6 +106,15 @@ public function testInvalidInitialData()
$this->factory->create($this->formType, new \stdClass(), array('base64' => true));
}

/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "base64" with value "foo" is expected to be of type "bool"
*/
public function testInvalidBase64Option()
{
$this->factory->create($this->formType, null, array('base64' => 'foo'));
}

/**
* @return string
*/
Expand Down

0 comments on commit 79d36b8

Please sign in to comment.