diff --git a/lib/preview/txt.php b/lib/preview/txt.php index a487330691e05ce895920b55b11abed1e228068e..77e728eb3644d41476f2c38e3e07c0c5bd10388d 100644 --- a/lib/preview/txt.php +++ b/lib/preview/txt.php @@ -9,11 +9,21 @@ namespace OC\Preview; class TXT extends Provider { + private static $blacklist = array( + 'text/calendar', + 'text/vcard', + ); + public function getMimeType() { return '/text\/.*/'; } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + $mimetype = $fileview->getMimeType($path); + if(in_array($mimetype, self::$blacklist)) { + return false; + } + $content = $fileview->fopen($path, 'r'); $content = stream_get_contents($content); diff --git a/tests/data/testcal.ics b/tests/data/testcal.ics new file mode 100644 index 0000000000000000000000000000000000000000..e05f01ba1c2755e9c7f02a6959e107fc2d97c61a --- /dev/null +++ b/tests/data/testcal.ics @@ -0,0 +1,13 @@ +BEGIN:VCALENDAR +PRODID:-//some random cal software//EN +VERSION:2.0 +BEGIN:VEVENT +CREATED:20130102T120000Z +LAST-MODIFIED:20130102T120000Z +DTSTAMP:20130102T120000Z +UID:f106ecdf-c716-43ef-9d94-4e6f19f2fcfb +SUMMARY:a test cal file +DTSTART;VALUE=DATE:20130101 +DTEND;VALUE=DATE:20130102 +END:VEVENT +END:VCALENDAR \ No newline at end of file diff --git a/tests/data/testcontact.vcf b/tests/data/testcontact.vcf new file mode 100644 index 0000000000000000000000000000000000000000..2af963d6916eecf7d2ee39a2c3018f64b171c6e6 --- /dev/null +++ b/tests/data/testcontact.vcf @@ -0,0 +1,6 @@ +BEGIN:VCARD +VERSION:3.0 +PRODID:-//some random contact software//EN +N:def;abc;;; +FN:abc def +END:VCARD \ No newline at end of file diff --git a/tests/lib/preview.php b/tests/lib/preview.php index bebdc12b5004baf61bcb644f6a1936ebe621e226..d0cdd2c44fba78c7031333e4132117a70f3a9344 100644 --- a/tests/lib/preview.php +++ b/tests/lib/preview.php @@ -92,6 +92,47 @@ class Preview extends \PHPUnit_Framework_TestCase { $this->assertEquals($image->height(), $maxY); } + public function txtBlacklist() { + $txt = 'random text file'; + $ics = file_get_contents(__DIR__ . '/../data/testcal.ics'); + $vcf = file_get_contents(__DIR__ . '/../data/testcontact.vcf'); + + return array( + array('txt', $txt, false), + array('ics', $ics, true), + array('vcf', $vcf, true), + ); + } + + /** + * @dataProvider txtBlacklist + */ + public function testIsTransparent($extension, $data, $expectedResult) { + $user = $this->initFS(); + + $rootView = new \OC\Files\View(''); + $rootView->mkdir('/'.$user); + $rootView->mkdir('/'.$user.'/files'); + + $x = 32; + $y = 32; + + $sample = '/'.$user.'/files/test.'.$extension; + $rootView->file_put_contents($sample, $data); + $preview = new \OC\Preview($user, 'files/', 'test.'.$extension, $x, $y); + $image = $preview->getPreview(); + $resource = $image->resource(); + + //http://stackoverflow.com/questions/5702953/imagecolorat-and-transparency + $colorIndex = imagecolorat($resource, 1, 1); + $colorInfo = imagecolorsforindex($resource, $colorIndex); + $this->assertEquals( + $expectedResult, + $colorInfo['alpha'] === 127, + 'Failed asserting that only previews for text files are transparent.' + ); + } + private function initFS() { if(\OC\Files\Filesystem::getView()){ $user = \OC_User::getUser(); @@ -105,4 +146,4 @@ class Preview extends \PHPUnit_Framework_TestCase { return $user; } -} \ No newline at end of file +}