Skip to content

Commit

Permalink
Fix Magento 2 bug: Dots are not supported in filenames.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoryHogeveen authored Dec 24, 2024
1 parent 4e42476 commit 37de12e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Model/MediaGalleryProcessorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ public function _createImageContent()
return $imageFactory->create();
}


/**
* Fix Magento 2 bug: Dots are not supported in filenames.
* Report: https://github.com/magento/magento2/issues/39505
*/
public function parseFilename( string $file ): string
{
$name = pathinfo( $file, PATHINFO_FILENAME );
$extension = pathinfo( $file, PATHINFO_EXTENSION );
return str_replace( '.', '', $name ) . '.' . $extension;
}

/**
* @param $url
*
Expand All @@ -119,8 +131,8 @@ public function fetchImageContentFromUrl( $url )
throw new InputException( __( 'SyncEngine: URL not a file: ' . $url ) );
}

$name = pathinfo( $url, PATHINFO_FILENAME );
$image = base64_encode( $curl->getBody() );
$name = $this->parseFilename( $url );
$image = base64_encode( $curl->getBody() );

return $this->_createImageContent()->setType( $mimeType )->setName( $name )->setBase64EncodedData( $image );
}
Expand Down Expand Up @@ -148,7 +160,7 @@ public function fetchImageContentFromPath( $path )

$message = '';
try {
$name = pathinfo( $file, PATHINFO_FILENAME );
$name = $this->parseFilename( $file );
$image = base64_encode( $fs->fileGetContents( $file ) );
$mimeType = mime_content_type( $file );
} catch ( InputException $e ) {
Expand Down

0 comments on commit 37de12e

Please sign in to comment.