Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Sanitize asset folder name on creation #10577

Merged
merged 6 commits into from
Aug 8, 2024

Conversation

daun
Copy link
Contributor

@daun daun commented Aug 6, 2024

When uploading assets, the filenames are automatically sanitized. This does the same for asset folders.

Closes statamic/ideas#503

Screen Recording 2024-08-06 at 14 24 12

Current behavior

Currently a completely valid folder name is required when creating/moving/renaming folders. Spaces in folder names lead to validation errors and require manual correction. This quickly becomes exhausting when editors need to create dozens of folders by copy-pasting from their local filesystem.

Behavior after this change

With this change, folder name inputs allow spaces. For that, it introduces a new rule for valid folder name inputs: same as alpha_dash, but with spaces allowed. The spaces are then removed by re-using the basename sanitizer from the FileUploader class, which also sanitizes upload filenames. Handles creation and renaming/moving.

Notes

Wasn't sure about the rule name AllowedFolder as it implies a check for a valid filesystem directory name, when actually it validates the pre-sanitized input value of folder name inputs.

@daun

This comment was marked as outdated.

@daun daun marked this pull request as draft August 6, 2024 12:42
@daun daun marked this pull request as ready for review August 6, 2024 13:24
@jasonvarga
Copy link
Member

Wasn't sure about the rule name AllowedFolder

We could just call the rule AlphaDashSpaces ?

@daun
Copy link
Contributor Author

daun commented Aug 7, 2024

Renamed the validation rule, ready from my end :)

@jasonvarga jasonvarga merged commit dff7005 into statamic:5.x Aug 8, 2024
17 checks passed
@daun daun deleted the feature/sanitize-folder-names branch October 13, 2024 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrite folder names automatically when creating asset folders
2 participants