From c2488c31466ec99647ff06f455b35de4162383c1 Mon Sep 17 00:00:00 2001 From: mikaelkael Date: Fri, 16 Jul 2010 20:04:29 +0000 Subject: [PATCH 1/2] ZF-9108: remove rendered
in captcha image git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22583 44c647ce-9c0f-0410-b52a-842ac1e357ba --- src/Image.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Image.php b/src/Image.php index 7703482..7d708b5 100644 --- a/src/Image.php +++ b/src/Image.php @@ -595,6 +595,7 @@ protected function _gc() */ public function render(Zend_View_Interface $view = null, $element = null) { - return ''.$this->getImgAlt().'
'; + return '' . $this->getImgAlt()
+             . ''; } } From 19e8e525e7260d6c92d10d155f9b15f15c7136a3 Mon Sep 17 00:00:00 2001 From: mikaelkael Date: Fri, 16 Jul 2010 20:51:51 +0000 Subject: [PATCH 2/2] ZF-10006: Zend_Captcha_Image::_gc() removes only captcha files identified by their suffix git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22589 44c647ce-9c0f-0410-b52a-842ac1e357ba --- src/Image.php | 6 +++++- test/ImageTest.php | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Image.php b/src/Image.php index 7d708b5..c917246 100644 --- a/src/Image.php +++ b/src/Image.php @@ -577,10 +577,14 @@ protected function _gc() // safety guard return; } + $suffixLength = strlen($this->_suffix); foreach (new DirectoryIterator($imgdir) as $file) { if (!$file->isDot() && !$file->isDir()) { if ($file->getMTime() < $expire) { - unlink($file->getPathname()); + // only deletes files ending with $this->_suffix + if (substr($file->getFilename(), -($suffixLength)) == $this->_suffix) { + unlink($file->getPathname()); + } } } } diff --git a/test/ImageTest.php b/test/ImageTest.php index 001d7ff..835b19c 100644 --- a/test/ImageTest.php +++ b/test/ImageTest.php @@ -219,6 +219,27 @@ public function testCaptchaImageCleanup() $this->assertFalse(file_exists($filename), "File $filename was found even after GC"); } + /** + * @group ZF-10006 + */ + public function testCaptchaImageCleanupOnlyCaptchaFilesIdentifiedByTheirSuffix() + { + $this->element->render($this->getView()); + $filename = $this->testDir."/".$this->captcha->getId().".png"; + $this->assertTrue(file_exists($filename)); + //Create other cache file + $otherFile = $this->testDir . "/zf10006.cache"; + file_put_contents($otherFile, ''); + $this->assertTrue(file_exists($otherFile)); + $this->captcha->setExpiration(1); + $this->captcha->setGcFreq(1); + sleep(2); + $this->captcha->generate(); + clearstatcache(); + $this->assertFalse(file_exists($filename), "File $filename was found even after GC"); + $this->assertTrue(file_exists($otherFile), "File $otherFile was not found after GC"); + } + public function testGenerateReturnsId() { $id = $this->captcha->generate();