Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Check that pathinfo() has returned an extension #294

Merged
merged 1 commit into from

2 participants

Rob Allen Frank Brückner
Rob Allen
Collaborator

Prevent the notice that is generated when pathinfo() doesn't return an
'extension' element in Zend_Validate_File_Extension.

Fixes #287

Rob Allen akrabat Check that pathinfo() has returned an extension
Prevent the notice that is generated when pathinfo() doesn't return an
'extension' element in Zend_Validate_File_Extension.

Fixes #287
135cc91
Frank Brückner froschdesign merged commit 502f670 into from
Frank Brückner froschdesign self-assigned this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 7, 2014
  1. Rob Allen

    Check that pathinfo() has returned an extension

    akrabat authored
    Prevent the notice that is generated when pathinfo() doesn't return an
    'extension' element in Zend_Validate_File_Extension.
    
    Fixes #287
This page is out of date. Refresh to see the latest.
6 library/Zend/Validate/File/Extension.php
View
@@ -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();
21 tests/Zend/Validate/File/ExtensionTest.php
View
@@ -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(
1  tests/Zend/Validate/File/_files/no_extension
View
@@ -0,0 +1 @@
+This file has no extension.
Something went wrong with that request. Please try again.