statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
4.13k stars 540 forks source link

Files Fieldtype: `max_files: 1` doesn't prevent uploading more than 1 file #11197

Open duncanmcclean opened 1 day ago

duncanmcclean commented 1 day ago

Bug description

I discovered this while working on statamic/importer#47.

When you have a Files fieldtype, with max_files: 1, it allows you to upload multiple files, when it should only let you upload the one.

https://github.com/user-attachments/assets/205aac40-16d0-43e7-8247-214ae8930974

How to reproduce

  1. Add a Files fieldtype with max_files: 1 (it's a hidden fieldtype, so you'll need to add it to your blueprint manually):
-
  handle: file
  field:
    type: files
    max_files: 1

Logs

No response

Environment

Environment
Application Name: Statamic
Laravel Version: 11.30.0
PHP Version: 8.3.14
Composer Version: 2.8.3
Environment: local
Debug Mode: ENABLED
URL: importer-sandbox.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: log
Queue: sync
Session: file

Statamic
Addons: 1
Sites: 2 (Statamic, German)
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.37.0 PRO

Statamic Addons
statamic/importer: 1.4.1

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

duncanmcclean commented 1 day ago

As a workaround, you can add a max: 1 validation rule to ensure only 1 file can actually be uploaded.