Fix: preserve file extension when upload_translit is enabled - #91
Open
Ibochkarev wants to merge 3 commits into
Open
Fix: preserve file extension when upload_translit is enabled#91Ibochkarev wants to merge 3 commits into
Ibochkarev wants to merge 3 commits into
Conversation
Extract translit logic to applyUploadTranslitToFile, use filterFilename for basename-only filtering so extension is preserved. Add modX::filterFilename for upload-specific character restriction. Refs modxcms#16787
Stop truncating uploaded filenames via friendly_alias_max_length so extensions stay intact. Drop the filterFilename pathinfo split and cover the modxcms#16787 regression in modMediaSourceTest.
Split uploaded names with pathinfo so FURL rules cannot rewrite or strip the extension, keep max_length disabled for uploads, and cover alphanumeric restrict in tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Что сделано
При включённом
upload_translitзапускаем FURL-фильтрацию только на basename и возвращаем оригинальное расширение. Правила alias больше не сжёвывают.jpg.applyUploadTranslitToFile()делает работу: сплитpathinfo(),friendly_alias_max_length => 0(имена загрузок игнорируют cap длины FURL),filterPathSegment()на basename, затем пересобираем имя и срабатываемOnFileManagerFileRename, если изменилось. Dotfiles вроде.htaccessи пустые результаты фильтра держат оригинальное имя.modMediaSourceTestпокрывает кейс длинного имени + max_length, alphanumeric-ограничение (photo.jpg), составные имена, lowercase basename и имена без расширения.Зачем нужно
upload_translit+friendly_alias_max_lengthраньше обрезали всё имя файла.verylongfilename.jpgстановилсяverylongfilenam, терял расширение и ломал delete / MoreGallery. Приfriendly_alias_restrict_chars=alphaилиalphanumericтот же full-name-путь превращалphoto.jpgвphoto-jpg.Refs modxcms#16787.
Как проверить
upload_translit.friendly_alias_max_lengthпоменьше (15).verylongfilename.jpg.verylongfilename.jpg.friendly_alias_restrict_charsвalphanumeric, загрузитеphoto.jpg, проверьте, что остаётсяphoto.jpg.modMediaSourceTestдля автоматической проверки.Связанные
Оригинал: modxcms#16826