kartik-v / yii2-export

A library to export server/db data in various formats (e.g. excel, html, pdf, csv etc.)
http://demos.krajee.com/export
Other
165 stars 126 forks source link

Cyrilic symbols in filename produce notice #324

Closed bscheshirwork closed 4 years ago

bscheshirwork commented 4 years ago

Prerequisites

Steps to reproduce the issue

  1. filename
    
        <?= ExportMenu::widget([
    ...
            'filename' => 'Список заявок', // non-latin produce notice
    ...
        ]); ?>
2. try to download
3. catch notice

## Expected behavior and actual behavior

When I follow those steps, I see...

PHP Notice – yii\base\ErrorException iconv(): Detected an illegal character in input string

  1. in /app/vendor/kartik-v/yii2-export/src/ExportMenu.phpat line 802 793794795796797798799800801802803804805806807808809810811 } } $this->raiseEvent('onRenderSheet', [$sheet, $this]); $this->folder = trim(Yii::getAlias($this->folder)); if (!file_exists($this->folder) && !mkdir($this->folder, 0777, true)) { throw new InvalidConfigException( "Invalid permissions to write to '{$this->folder}' as set in ExportMenu::folder property." ); } $filename = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $this->filename); $file = self::slash($this->folder) . $filename . '.' . $config['extension']; if ($this->stream) { $this->clearOutputBuffers(); } $writer->save($file); if ($this->stream) { $this->setHttpHeaders(); $this->clearOutputBuffers(); readfile($file);

I was expecting...
Download sucessful

note: ignoring error provide correct result
https://github.com/kartik-v/yii2-export/blob/f76c63e4f60661655ced726dc758a36da4182abc/src/ExportMenu.php#L802
    $filename = @iconv("UTF-8", "ISO-8859-1//TRANSLIT", $this->filename);
also  `//TRANSLIT`  -> `//IGNORE`  have same effect
    $filename = iconv("UTF-8", "ISO-8859-1//IGNORE", $this->filename);


## Environment

#### Browsers

- [ ] Google Chrome
- [ ] Mozilla Firefox
- [ ] Internet Explorer
- [ ] Safari

#### Operating System

- [ ] Windows
- [ ] Mac OS X
- [ ] Linux
- [ ] Mobile

#### Libraries

- jQuery version:
- yii2-export version: kartik-v/yii2-export dev-master A library to export server/db data in various formats (e.g. excel, html, pdf, csv etc.)

## Isolating the problem

- [ ] This bug happens [on the demos page](https://demos.krajee.com/export-demo)
- [ ] The bug happens consistently across all tested browsers
- [ ] This bug happens when using yii2-export without other plugins.

<bountysource-plugin>

---
Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/91584520-cyrilic-symbols-in-filename-produce-notice?utm_campaign=plugin&utm_content=tracker%2F7668315&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F7668315&utm_medium=issues&utm_source=github).
</bountysource-plugin>
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.