added hhvm specific hack, #329

This commit is contained in:
madflow 2016-10-17 16:29:42 +02:00
parent 9989616772
commit 9f3c29e6be
2 changed files with 17 additions and 5 deletions

View File

@ -4,9 +4,6 @@ namespace Box\Spout\Common\Escaper;
use Box\Spout\Common\Singleton;
// HVM hack https://github.com/box/spout/issues/329
defined('ENT_DISALLOWED') || define('ENT_DISALLOWED', 128);
/**
* Class ODS
* Provides functions to escape and unescape data for ODS files
@ -25,7 +22,15 @@ class ODS implements EscaperInterface
*/
public function escape($string)
{
return htmlspecialchars($string, ENT_QUOTES | ENT_DISALLOWED);
if (defined('ENT_DISALLOWED')) {
return htmlspecialchars($string, ENT_QUOTES | ENT_DISALLOWED);
} else {
// We are on hhvm or any other engine that does not support ENT_DISALLOWED
// https://github.com/box/spout/issues/329
$escapedString = htmlspecialchars($string, ENT_QUOTES);
$replacedString = preg_replace('/[\x00-\x08\x0B-\x0C\x0E-\x1F]/', '<27>', $escapedString);
return $replacedString;
}
}
/**

View File

@ -468,10 +468,11 @@ class WriterTest extends \PHPUnit_Framework_TestCase
$reader->open($resourcePath);
$canBeRead = false;
$rowsRead = [];
try {
foreach ($reader->getSheetIterator() as $sheetIndex => $sheet) {
foreach ($sheet->getRowIterator() as $rowIndex => $row) {
$rowsRead[] = $row;
}
}
$canBeRead = true;
@ -479,6 +480,12 @@ class WriterTest extends \PHPUnit_Framework_TestCase
} catch(\Exception $e) {}
$this->assertTrue($canBeRead, 'The file with illegal chars can be read');
$dataRowsExpected = [
['I am a text'],
['I am a vertical tab:<3A>'],
['I am a form feed:<3A>'],
];
$this->assertEquals($dataRowsExpected, $rowsRead, 'Correct rows with unicode replacement are read');
}
/**