Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/25' into develop
Browse files Browse the repository at this point in the history
Close #25
  • Loading branch information
weierophinney committed Apr 25, 2018
2 parents a28301c + aa8cbe9 commit 9a572d1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -10,7 +10,8 @@ All notable changes to this project will be documented in this file, in reverse

### Changed

- Nothing.
- [#25](https://github.com/zendframework/zend-escaper/pull/25) changes the behavior of the `Escaper` constructor; it now raises an
exception for non-null, non-string `$encoding` arguments.

### Deprecated

Expand Down
6 changes: 5 additions & 1 deletion src/Escaper.php
Expand Up @@ -95,7 +95,11 @@ class Escaper
public function __construct($encoding = null)
{
if ($encoding !== null) {
$encoding = (string) $encoding;
if (! is_string($encoding)) {
throw new Exception\InvalidArgumentException(
get_class($this) . ' constructor parameter must be a string, received ' . gettype($encoding)
);
}
if ($encoding === '') {
throw new Exception\InvalidArgumentException(
get_class($this) . ' constructor parameter does not allow a blank value'
Expand Down
9 changes: 9 additions & 0 deletions test/EscaperTest.php
Expand Up @@ -180,6 +180,15 @@ public function setUp()
$this->escaper = new Escaper('UTF-8');
}

/**
* @expectedException \Zend\Escaper\Exception\InvalidArgumentException
* @expectedExceptionMessage Zend\Escaper\Escaper constructor parameter must be a string, received integer
*/
public function testSettingEncodingToNonStringShouldThrowException()
{
$escaper = new Escaper(1);
}

/**
* @expectedException \Zend\Escaper\Exception\InvalidArgumentException
*/
Expand Down

0 comments on commit 9a572d1

Please sign in to comment.