mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-10-31 18:47:33 +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) | - 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 #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) | - 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++) { |             for (var index=0; index < options.extensions.length; index++) { | ||||||
|                 var ext = options.extensions[index].toLowerCase(); |                 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; |                     found = true; | ||||||
|                     break; |                     break; | ||||||
|                 } |                 } | ||||||
|  | |||||||
| @ -415,7 +415,7 @@ class FileValidator extends Validator | |||||||
|  |  | ||||||
|         if (!empty($this->extensions)) { |         if (!empty($this->extensions)) { | ||||||
|             foreach ((array) $this->extensions as $ext) { |             foreach ((array) $this->extensions as $ext) { | ||||||
|                 if (StringHelper::endsWith($file->name, ".$ext", false)) { |                 if ($extension === $ext || StringHelper::endsWith($file->name, ".$ext", false)) { | ||||||
|                     return true; |                     return true; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  | |||||||
| @ -452,6 +452,27 @@ class FileValidatorTest extends TestCase | |||||||
|         $this->assertNotFalse(stripos(current($m->getErrors('attr_exe')), 'Only files with these extensions ')); |         $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() |     public function testValidateAttributeDoubleType() | ||||||
|     { |     { | ||||||
|         $val = new FileValidator([ |         $val = new FileValidator([ | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 DarkDef
					DarkDef