diff options
author | ignace nyamagana butera <nyamsprod@gmail.com> | 2016-02-12 19:27:48 +0100 |
---|---|---|
committer | ignace nyamagana butera <nyamsprod@gmail.com> | 2016-02-12 19:27:48 +0100 |
commit | 8f18ddedefff4d2ca5c09cc591cba4798d906c14 (patch) | |
tree | 09dc060b02727917d19855b9de46530a97e082fa | |
parent | 0a1b535df48507f58ed3c7ab44e72272b11163ac (diff) | |
parent | 7ad49fd61243fbfbbdf140c9e596c90675aaf474 (diff) | |
download | csv-8f18ddedefff4d2ca5c09cc591cba4798d906c14.zip csv-8f18ddedefff4d2ca5c09cc591cba4798d906c14.tar.gz csv-8f18ddedefff4d2ca5c09cc591cba4798d906c14.tar.bz2 |
Merge pull request #152 from thephpleague/bugfix/streamfilter
Bugfix Library
-rw-r--r-- | CHANGELOG.md | 20 | ||||
-rw-r--r-- | src/AbstractCsv.php | 2 | ||||
-rw-r--r-- | src/Config/Output.php | 42 | ||||
-rw-r--r-- | src/Modifier/QueryFilter.php | 6 | ||||
-rw-r--r-- | src/Modifier/StreamFilter.php | 10 | ||||
-rw-r--r-- | test/StreamFilterTest.php | 7 |
6 files changed, 72 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 46894f4..0eee0b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,26 @@ All Notable changes to `Csv` will be documented in this file +## Next - 2016-xx-xx + +### Added + +- `Ouput::getInputEncoding` +- `Ouput::setInputEncoding` + +### Deprecated + +- `Ouput::getEncodingFrom` replaced by `Ouput::getInputEncoding` +- `Ouput::setEncodingFrom` replaced by `Ouput::setInputEncoding` + +### Fixed + +- Stream Filters are now url encoded before usage [issue #72](https://github.com/thephpleague/csv/issues/72) + +### Removed + +- None + ## 8.0.0 - 2015-12-11 ### Added diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php index 51b0df1..c9ac691 100644 --- a/src/AbstractCsv.php +++ b/src/AbstractCsv.php @@ -190,7 +190,7 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate $csv->delimiter = $this->delimiter; $csv->enclosure = $this->enclosure; $csv->escape = $this->escape; - $csv->encodingFrom = $this->encodingFrom; + $csv->input_encoding = $this->input_encoding; $csv->input_bom = $this->input_bom; $csv->output_bom = $this->output_bom; $csv->newline = $this->newline; diff --git a/src/Config/Output.php b/src/Config/Output.php index 2e1faf3..6c0471f 100644 --- a/src/Config/Output.php +++ b/src/Config/Output.php @@ -33,7 +33,7 @@ trait Output * * @var string */ - protected $encodingFrom = 'UTF-8'; + protected $input_encoding = 'UTF-8'; /** * The Input file BOM character @@ -54,26 +54,56 @@ trait Output * * @return static */ - public function setEncodingFrom($str) + public function setInputEncoding($str) { $str = str_replace('_', '-', $str); $str = filter_var($str, FILTER_SANITIZE_STRING, ['flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH]); if (empty($str)) { throw new InvalidArgumentException('you should use a valid charset'); } - $this->encodingFrom = strtoupper($str); + $this->input_encoding = strtoupper($str); return $this; } /** + * Sets the CSV encoding charset + * + * DEPRECATION WARNING! This method will be removed in the next major point release + * + * @deprecated deprecated since version 4.1 + * + * @param string $str + * + * @return static + */ + public function setEncodingFrom($str) + { + return $this->setInputEncoding($str); + } + + /** + * Gets the source CSV encoding charset + * + * @return string + */ + public function getInputEncoding() + { + return $this->input_encoding; + } + + /** * Gets the source CSV encoding charset * + * DEPRECATION WARNING! This method will be removed in the next major point release + * + * @deprecated deprecated since version 4.1 + * * @return string */ public function getEncodingFrom() { - return $this->encodingFrom; + return $this->input_encoding; } /** @@ -219,12 +249,12 @@ trait Output */ protected function convertToUtf8(Iterator $iterator) { - if (stripos($this->encodingFrom, 'UTF-8') !== false) { + if (stripos($this->input_encoding, 'UTF-8') !== false) { return $iterator; } $convertCell = function ($value) { - return mb_convert_encoding($value, 'UTF-8', $this->encodingFrom); + return mb_convert_encoding($value, 'UTF-8', $this->input_encoding); }; $convertRow = function (array $row) use ($convertCell) { diff --git a/src/Modifier/QueryFilter.php b/src/Modifier/QueryFilter.php index daaaa89..72e9104 100644 --- a/src/Modifier/QueryFilter.php +++ b/src/Modifier/QueryFilter.php @@ -76,7 +76,7 @@ trait QueryFilter } /** - * {@inheritdoc} + * @inheritdoc */ abstract public function getInputBom(); @@ -142,7 +142,7 @@ trait QueryFilter } /** - * {@inheritdoc} + * @inheritdoc */ abstract public function getEnclosure(); @@ -167,7 +167,7 @@ trait QueryFilter } /** - * {@inheritdoc} + * @inheritdoc */ abstract public function getIterator(); diff --git a/src/Modifier/StreamFilter.php b/src/Modifier/StreamFilter.php index 030523a..e07d2bc 100644 --- a/src/Modifier/StreamFilter.php +++ b/src/Modifier/StreamFilter.php @@ -83,7 +83,7 @@ trait StreamFilter return; } $this->stream_uri = $matches['resource']; - $this->stream_filters = explode('|', $matches['filters']); + $this->stream_filters = array_map('urldecode', explode('|', $matches['filters'])); $this->stream_filter_mode = $this->fetchStreamModeAsInt($matches['mode']); } @@ -209,7 +209,7 @@ trait StreamFilter { $this->assertStreamable(); - return $this->validateString($filter_name); + return urldecode($this->validateString($filter_name)); } /** @@ -228,7 +228,7 @@ trait StreamFilter { $this->assertStreamable(); - return false !== array_search($filter_name, $this->stream_filters, true); + return false !== array_search(urldecode($filter_name), $this->stream_filters, true); } /** @@ -241,7 +241,7 @@ trait StreamFilter public function removeStreamFilter($filter_name) { $this->assertStreamable(); - $res = array_search($filter_name, $this->stream_filters, true); + $res = array_search(urldecode($filter_name), $this->stream_filters, true); if (false !== $res) { unset($this->stream_filters[$res]); } @@ -276,7 +276,7 @@ trait StreamFilter return 'php://filter/' .$this->getStreamFilterPrefix() - .implode('|', $this->stream_filters) + .implode('|', array_map('urlencode', $this->stream_filters)) .'/resource='.$this->stream_uri; } diff --git a/test/StreamFilterTest.php b/test/StreamFilterTest.php index e576a02..0b98050 100644 --- a/test/StreamFilterTest.php +++ b/test/StreamFilterTest.php @@ -142,4 +142,11 @@ class StreamFilterTest extends AbstractTestCase $this->assertTrue($csv->hasStreamFilter(FilterReplace::FILTER_NAME."\r\n:\n")); $csv->insertOne([1, 'two', 3, "new\r\nline"]); } + + public function testUrlEncodeFilterParameters() + { + $csv = Reader::createFromPath(__DIR__.'/data/foo.csv'); + $csv->appendStreamFilter('convert.iconv.UTF-8/ASCII//TRANSLIT'); + $this->assertCount(1, $csv->fetchAll()); + } } |