Skip to content

Commit

Permalink
[4.4] [bug] Media manager misbehaves on files with capitalized extens…
Browse files Browse the repository at this point in the history
…ions (#43336)

* a

* b

* Update LocalAdapter.php
  • Loading branch information
dgrammatiko authored Apr 26, 2024
1 parent 43293d0 commit bd6ca75
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/media_source/com_media/js/edit-images.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class Edit {
* Public
*/
upload(url, stateChangeCallback) {
let format = Joomla.MediaManager.Edit.original.extension === 'jpg' ? 'jpeg' : Joomla.MediaManager.Edit.original.extension;
let format = Joomla.MediaManager.Edit.original.extension.toLowerCase() === 'jpg' ? 'jpeg' : Joomla.MediaManager.Edit.original.extension.toLowerCase();

if (!format) {
// eslint-disable-next-line prefer-destructuring
Expand Down
2 changes: 1 addition & 1 deletion build/media_source/plg_media-action_crop/js/crop.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const init = (image) => {
formElements.cropY.value = Math.round(e.detail.y);
formElements.cropWidth.value = Math.round(e.detail.width);
formElements.cropHeight.value = Math.round(e.detail.height);
const format = Joomla.MediaManager.Edit.original.extension === 'jpg' ? 'jpeg' : Joomla.MediaManager.Edit.original.extension;
const format = Joomla.MediaManager.Edit.original.extension.toLowerCase() === 'jpg' ? 'jpeg' : Joomla.MediaManager.Edit.original.extension.toLowerCase();
const quality = formElements.cropQuality.value;

// Update the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const resize = (width, height, image) => {
canvas.getContext('2d').drawImage(image, 0, 0, width, height);

// The format
const format = Joomla.MediaManager.Edit.original.extension === 'jpg' ? 'jpeg' : Joomla.MediaManager.Edit.original.extension;
const format = Joomla.MediaManager.Edit.original.extension.toLowerCase() === 'jpg' ? 'jpeg' : Joomla.MediaManager.Edit.original.extension.toLowerCase();

// The quality
const quality = formElements.resizeQuality.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const rotate = (angle, image) => {
ctx.drawImage(image, -image.naturalWidth / 2, -image.naturalHeight / 2);

// The format
const format = Joomla.MediaManager.Edit.original.extension === 'jpg' ? 'jpeg' : 'jpg';
const format = Joomla.MediaManager.Edit.original.extension.toLowerCase() === 'jpg' ? 'jpeg' : Joomla.MediaManager.Edit.original.extension.toLowerCase();

// The quality
const quality = document.getElementById('jform_rotate_quality').value;
Expand Down
3 changes: 3 additions & 0 deletions libraries/src/Helper/MediaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ public function canUpload($file, $component = 'com_media', $allowedExecutables =
$executables = array_diff($executables, $allowedExecutables);
}

// Ensure lowercase extension
$filetypes = array_map('strtolower', $filetypes);

$check = array_intersect($filetypes, $executables);

if (!empty($check)) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/filesystem/local/src/Adapter/LocalAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ private function checkContent(string $localPath, string $mediaContent)
$helper = new MediaHelper();

// @todo find a better way to check the input, by not writing the file to the disk
$tmpFile = Path::clean(dirname($localPath) . '/' . uniqid() . '.' . File::getExt($name));
$tmpFile = Path::clean(\dirname($localPath) . '/' . uniqid() . '.' . strtolower(File::getExt($name)));

if (!File::write($tmpFile, $mediaContent)) {
throw new \Exception(Text::_('JLIB_MEDIA_ERROR_UPLOAD_INPUT'), 500);
Expand Down

0 comments on commit bd6ca75

Please sign in to comment.