mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-10-31 10:39:59 +08:00 
			
		
		
		
	Fix #18239: Fix support of no-extension files for FileValidator::validateExtension()
				
					
				
			This commit is contained in:
		| @ -6,6 +6,7 @@ Yii Framework 2 Change Log | ||||
|  | ||||
| - Enh #18236: Allow `yii\filters\RateLimiter` to accept a closure function for the `$user` property in order to assign values on runtime (nadar) | ||||
| - Bug #18233: Add PHP 8 support (samdark) | ||||
| - Bug #18239: Fix support of no-extension files for `FileValidator::validateExtension()` (darkdef) | ||||
| - Bug #18229: Add flag for recognize SyBase databases on uses pdo_dblib (darkdef) | ||||
|  | ||||
|  | ||||
|  | ||||
| @ -413,7 +413,7 @@ yii.validation = (function ($) { | ||||
|  | ||||
|             for (var index=0; index < options.extensions.length; index++) { | ||||
|                 var ext = options.extensions[index].toLowerCase(); | ||||
|                 if (filename.substr(filename.length - options.extensions[index].length - 1) === ('.' + ext)) { | ||||
|                 if ((ext === '' && filename.indexOf('.') === -1) || (filename.substr(filename.length - options.extensions[index].length - 1) === ('.' + ext))) { | ||||
|                     found = true; | ||||
|                     break; | ||||
|                 } | ||||
|  | ||||
| @ -415,7 +415,7 @@ class FileValidator extends Validator | ||||
|  | ||||
|         if (!empty($this->extensions)) { | ||||
|             foreach ((array) $this->extensions as $ext) { | ||||
|                 if (StringHelper::endsWith($file->name, ".$ext", false)) { | ||||
|                 if ($extension === $ext || StringHelper::endsWith($file->name, ".$ext", false)) { | ||||
|                     return true; | ||||
|                 } | ||||
|             } | ||||
|  | ||||
| @ -452,6 +452,27 @@ class FileValidatorTest extends TestCase | ||||
|         $this->assertNotFalse(stripos(current($m->getErrors('attr_exe')), 'Only files with these extensions ')); | ||||
|     } | ||||
|  | ||||
|     public function testValidateEmptyExtension() | ||||
|     { | ||||
|         $val = new FileValidator([ | ||||
|             'extensions' => ['txt', ''], | ||||
|             'checkExtensionByMimeType' => false, | ||||
|         ]); | ||||
|         $m = FakedValidationModel::createWithAttributes( | ||||
|             [ | ||||
|                 'attr_txt' => $this->createTestFiles([['name' => 'one.txt']]), | ||||
|                 'attr_empty' => $this->createTestFiles([['name' => 'bad.']]), | ||||
|                 'attr_empty2' => $this->createTestFiles([['name' => 'bad']]), | ||||
|             ] | ||||
|         ); | ||||
|         $val->validateAttribute($m, 'attr_txt'); | ||||
|         $this->assertFalse($m->hasErrors('attr_txt')); | ||||
|         $val->validateAttribute($m, 'attr_empty'); | ||||
|         $this->assertFalse($m->hasErrors('attr_empty')); | ||||
|         $val->validateAttribute($m, 'attr_empty2'); | ||||
|         $this->assertFalse($m->hasErrors('attr_empty2')); | ||||
|     } | ||||
|  | ||||
|     public function testValidateAttributeDoubleType() | ||||
|     { | ||||
|         $val = new FileValidator([ | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 DarkDef
					DarkDef