Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Commit

Permalink
Merge pull request #294 from akrabat/issue-287
Browse files Browse the repository at this point in the history
Fixes #287 - Check that pathinfo() has returned an extension
  • Loading branch information
froschdesign committed Mar 7, 2014
2 parents abc9a8e + 135cc91 commit 502f670
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions library/Zend/Validate/File/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ public function isValid($value, $file = null)
$info['extension'] = substr($file['name'], strrpos($file['name'], '.') + 1);
} else {
$info = pathinfo($value);
if (!array_key_exists('extension', $info)) {
// From the manual at http://php.net/pathinfo:
// "If the path does not have an extension, no extension element
// will be returned (see second example below)."
return false;
}
}

$extensions = $this->getExtension();
Expand Down
21 changes: 21 additions & 0 deletions tests/Zend/Validate/File/ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,27 @@ public function testBasic()
$this->assertTrue(array_key_exists('fileExtensionFalse', $validator->getMessages()));
}

/**
* GitHub issue #287
*
* pathinfo() does not guarantee that the extension index will be set
* according to the PHP manual (http://se2.php.net/pathinfo#example-2422).
*
* @return void
*/
public function testNoExtension()
{
$files = array(
'name' => 'no_extension',
'type' => 'text',
'size' => 200,
'tmp_name' => dirname(__FILE__) . '/_files/no_extension',
'error' => 0
);
$validator = new Zend_Validate_File_Extension('txt');
$this->assertEquals(false, $validator->isValid(dirname(__FILE__) . '/_files/no_extension'));
}

public function testZF3891()
{
$files = array(
Expand Down
1 change: 1 addition & 0 deletions tests/Zend/Validate/File/_files/no_extension
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file has no extension.

0 comments on commit 502f670

Please sign in to comment.