silverstripe-framework/tests/php/Core
Nick e456de11b0
Fix clobbering of the upload size validation (#10059)
* Fix clobbering of the upload size validation

When the validation is set here like this, it overrides validation which has already been setup with a simple '*' rule for the size based on PHP.

If you've defined in the sites yml config something like

    SilverStripe\Assets\Upload_Validator:
      default_max_file_size:
        '[image]': '2m'
        '*' : '1m'

then it will not be respected.

If you review SilverStripe\Assets\Upload_Validator and check the getAllowedMaxFileSize method, you'll see the sizing will be populated (if it hasn't been done before).

You can see it fail by;
- Setup a new SilverStripe site.
- Set your PHP to allow max post / max upload size of 10mb.
- Add the above config to your sites yml file and flush.
- In the CMS you'll be able to upload a 5MB file, when you shouldn't.

* Test that FileField will use size validation if defined

Couple of tests which prove a fix so the FileField and others will use the default_max_file_size setting

* Fix variable name in last commit

This is what happens when you refactor in the github window.
Fix the variable names. This will get squashed once merged.

* Updates the pr - white space and non deprecated method for byte conversion

Remove extra white space to appease the CS. Use the non deprecated method for memstring2bytes

* White space fixes for the phpcs

White space fixes for the phpcs

* Ensure that "memstring2bytes" can handle if an empty or value with no number is passed in

* DEP Bump assets constraint to ensure that change is also pulled in

---------

Co-authored-by: Guy Sartorelli <guy.sartorelli@silverstripe.com>
2024-01-08 15:49:41 +13:00
..
Cache FIX Get ApcuCacheFactory and MemcachedCacheFactory working again 2023-05-17 10:18:28 +12:00
ClassInfoTest FIX Harden hasMethod() against invalid values 2020-10-28 09:34:33 +13:00
Config API Remove deprecated code (#10594) 2022-12-08 10:44:47 +13:00
EnvironmentTest BUG Replace phpdotenv with thread-safe replacement 2017-10-20 18:43:11 +13:00
ExtensionTest FIX Allow removing named extensions in yaml config 2022-09-27 13:15:28 +13:00
Injector DEP Replace thirdparty simpletest with symfony domcrawler 2023-02-02 13:31:45 +13:00
Manifest MNT Remove TODO comments 2023-10-30 13:21:09 +13:00
ObjectTest Convert array delcarations to short array syntax 2020-04-20 18:58:09 +01:00
ClassInfoTest.php BUG include silverstripe core files into roots 2023-08-02 10:00:33 +12:00
ConvertTest.php Fix clobbering of the upload size validation (#10059) 2024-01-08 15:49:41 +13:00
CoreTest.php ENH PHP 8.1 compatibility 2022-04-14 13:12:59 +12:00
EnvironmentLoaderTest.php BUG Replace phpdotenv with thread-safe replacement 2017-10-20 18:43:11 +13:00
EnvironmentTest.php FIX Reduce array method calls 2023-03-22 11:06:23 +13:00
ExtensionTest.php FIX Allow removing named extensions in yaml config 2022-09-27 13:15:28 +13:00
HTMLCleanerTest.php Apply PSR2 / Namespace to remaining admin / tests 2016-12-19 16:08:19 +13:00
KernelTest.php BUG Fix unassigned nestedFrom 2017-07-21 08:58:19 +12:00
MemoryLimitTest.php ENH PHP 8.1 compatibility 2022-04-14 13:12:59 +12:00
ObjectTest.php MNT Remove TODO comments 2023-10-30 13:21:09 +13:00
PathTest.php ENH PHP 8.1 compatibility 2022-04-14 13:12:59 +12:00
PhpSyntaxTest.php MNT Remove TODO comments 2023-10-30 13:21:09 +13:00