Skip to content

Commit

Permalink
Prepare 9.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Oct 20, 2017
1 parent e7930ae commit efa1fc8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

All Notable changes to `Csv` will be documented in this file

## Next - TBD
## Next - 2017-10-20

### Added

- Support for non seekable stream. When seekable feature are required an exceptions will be thrown.
- `League\Csv\EncloseField` to force enclosure insertion on every field. [#269](https://github.com/thephpleague/csv/pull/269)
- `League\Csv\EscapeFormula` a Leage CSV formatter to prevent CSV Formula Injection in Spreadsheet programs.
- `League\Csv\EscapeFormula` a League CSV formatter to prevent CSV Formula Injection in Spreadsheet programs.
- `League\Csv\RFC4180Field::addTo` accept an option `$replace_whitespace` argument to improve RFC4180 compliance.
- `League\Csv\Abstract::getContent`
- `League\Csv\Abstract::getContent` to replace `League\Csv\Abstract::__toString`. The `__toString` method may trigger a Fatal Error with non seekable stream, instead you are recommended to used the new `getContent` method which will trigger an exception instead.

### Deprecated

Expand Down
24 changes: 16 additions & 8 deletions src/EscapeFormula.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@
class EscapeFormula
{
/**
* Special characters that will be escaped
* Spreadsheet formula starting character
*/
const FORMULA_STARTING_CHARS = ['=', '-', '+', '@'];

/**
* Effective Spreadsheet formula starting characters
*
* @var string[]
* @var array
*/
protected $special_chars = [];

/**
* Escape character
* Escape character to escape each CSV formula field
*
* @var string
*/
Expand All @@ -44,17 +49,20 @@ class EscapeFormula
/**
* New instance
*
* @param string $escape
* @param string[] $special_chars additional special characters to escape
* @param string $escape escape character to escape each CSV formula field
* @param string[] $special_chars additional spreadsheet formula starting characters
*
*/
public function __construct(string $escape = "\t", array $special_chars = [])
{
$this->escape = $escape;
if (!empty($special_chars)) {
$special_chars = $this->filterSpecialCharacters(...$special_chars);
}
$special_chars = array_merge(['=', '-', '+', '@'], $special_chars);
$this->special_chars = array_fill_keys(array_unique($special_chars), 1);

$chars = array_merge(self::FORMULA_STARTING_CHARS, $special_chars);
$chars = array_unique($chars);
$this->special_chars = array_fill_keys($chars, 1);
}

/**
Expand All @@ -69,7 +77,7 @@ public function __construct(string $escape = "\t", array $special_chars = [])
protected function filterSpecialCharacters(string ...$characters): array
{
foreach ($characters as $str) {
if (1 != mb_strlen($str)) {
if (1 != strlen($str)) {
throw new InvalidArgumentException(sprintf('The submitted string %s must be a single character', $str));
}
}
Expand Down

0 comments on commit efa1fc8

Please sign in to comment.