parent
dfcab0c13f
commit
962367c95f
|
@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Can read very small HTML files - [#194](https://github.com/PHPOffice/PhpSpreadsheet/issues/194)
|
||||||
|
|
||||||
## [1.0.0-beta2] - 2017-11-26
|
## [1.0.0-beta2] - 2017-11-26
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -112,8 +112,6 @@ class Html extends BaseReader
|
||||||
*
|
*
|
||||||
* @param string $pFilename
|
* @param string $pFilename
|
||||||
*
|
*
|
||||||
* @throws Exception
|
|
||||||
*
|
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canRead($pFilename)
|
public function canRead($pFilename)
|
||||||
|
@ -148,7 +146,14 @@ class Html extends BaseReader
|
||||||
$filename = $meta['uri'];
|
$filename = $meta['uri'];
|
||||||
|
|
||||||
$size = filesize($filename);
|
$size = filesize($filename);
|
||||||
|
if ($size === 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
$blockSize = self::TEST_SAMPLE_SIZE;
|
$blockSize = self::TEST_SAMPLE_SIZE;
|
||||||
|
if ($size < $blockSize) {
|
||||||
|
$blockSize = $size;
|
||||||
|
}
|
||||||
|
|
||||||
fseek($this->fileHandle, $size - $blockSize);
|
fseek($this->fileHandle, $size - $blockSize);
|
||||||
|
|
||||||
|
|
|
@ -13,4 +13,34 @@ class HtmlTest extends TestCase
|
||||||
$reader = new Html();
|
$reader = new Html();
|
||||||
self::assertFalse($reader->canRead($filename));
|
self::assertFalse($reader->canRead($filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function providerCanReadVerySmallFile()
|
||||||
|
{
|
||||||
|
$padding = str_repeat('a', 2048);
|
||||||
|
|
||||||
|
return [
|
||||||
|
[true, ' <html> ' . $padding . ' </html> '],
|
||||||
|
[true, ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>' . $padding . '</html>'],
|
||||||
|
[true, '<html></html>'],
|
||||||
|
[false, ''],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerCanReadVerySmallFile
|
||||||
|
*
|
||||||
|
* @param bool $expected
|
||||||
|
* @param string $content
|
||||||
|
*/
|
||||||
|
public function testCanReadVerySmallFile($expected, $content)
|
||||||
|
{
|
||||||
|
$filename = tempnam(sys_get_temp_dir(), 'html');
|
||||||
|
file_put_contents($filename, $content);
|
||||||
|
|
||||||
|
$reader = new Html();
|
||||||
|
$actual = $reader->canRead($filename);
|
||||||
|
unlink($filename);
|
||||||
|
|
||||||
|
self::assertSame($expected, $actual);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue