Could not open CSV file containing HTML fragment

We now always trust the file extension to avoid false positive of mime
detection for most simple cases. But we still try to guess the mime type
if the file extension does not match or is missing.

Fixes #564
This commit is contained in:
Adrien Crivelli
2018-06-25 11:12:27 +09:00
parent edb68ce05c
commit 9fdcaabe3c
5 changed files with 13 additions and 0 deletions
+1
View File
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Xlsx reader crashed when reading a file with workbook protection - [#553](https://github.com/PHPOffice/PhpSpreadsheet/pull/553)
- Cell formats with escaped spaces were causing incorrect date formatting - [#557](https://github.com/PHPOffice/PhpSpreadsheet/issues/557)
- Could not open CSV file containing HTML fragment - [##564](https://github.com/PHPOffice/PhpSpreadsheet/issues/564)
## [1.3.1] - 2018-06-12
+6
View File
@@ -507,6 +507,12 @@ class Csv extends BaseReader
fclose($this->fileHandle);
// Trust file extension if any
if (strtolower(pathinfo($pFilename, PATHINFO_EXTENSION)) === 'csv') {
return true;
}
// Attempt to guess mimetype
$type = mime_content_type($pFilename);
$supportedTypes = [
'text/csv',
@@ -83,6 +83,8 @@ class CsvTest extends TestCase
[false, 'data/Reader/Xml/WithoutStyle.xml'],
[true, 'data/Reader/CSV/enclosure.csv'],
[true, 'data/Reader/CSV/semicolon_separated.csv'],
[true, 'data/Reader/CSV/contains_html.csv'],
[true, 'data/Reader/CSV/csv_without_extension'],
[true, 'data/Reader/HTML/csv_with_angle_bracket.csv'],
[true, 'data/Reader/CSV/empty.csv'],
[true, '../samples/Reader/sampleData/example1.csv'],
+1
View File
@@ -0,0 +1 @@
"Column A";"<a href=''>Link</a>";"Column C"
1 Column A <a href=''>Link</a> Column C
@@ -0,0 +1,3 @@
This;Are;Headers
Cell A2;Number with comma;25,5
Two colons and a comma;B|3;:,: