yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.91k forks source link

FileValidator::validateExtension lost support of no-extension files #18239

Closed BelegUS closed 4 years ago

BelegUS commented 4 years ago

This was broken when fixing #18094. Changes made by @darkdef resulted in adding dot (.) to allowed extensions when comparing them to extension of file being uploaded. It's a problem on both:

  1. Server-side: https://github.com/yiisoft/yii2/blame/master/framework/validators/FileValidator.php#L418
  2. Client-side: https://github.com/yiisoft/yii2/blob/master/framework/assets/yii.validation.js#L416

What steps will reproduce the problem?

  1. Add to model a file validation rule with extensions => ['csv', 'txt', ''] configuration
  2. Try uploading a file with no extension using that model

    What is the expected result?

    Validator (both client-side and server-side) should allow uploading such file, as it was prior to 2.0.36 Yii2 version

    What do you get instead?

    A wrongExtension failed validation message is shown - validation fails and doesn't allow uploading the file without extension.

Additional info

Q A
Yii version 2.0.37
PHP version 7.2.31
Operating system Windows 10 Pro
BelegUS commented 4 years ago

Thank you @darkdef and @samdark! :)