Filename sanitation for non-ASCII encodings
-
Dear NextGen team,
First of all, I must say that this is an old issue (posts go back to two or three years) which so far has not been solved: I have been unable to find a solution, nor the problem has been fixed on further versions of the product.
The problem comes when you want to upload images which filename has non-ASCII characters (for instance, with accent marks in spanish but this could be extended to any other non-english language).
What is happening now is that, when uploading an image with that kind of filename, let’s say
samplé 3.jpg
, the classGalleryStorage_Driver_Base
performs a filename sanitation using WordPresssanitize_title_with_dashes
resultingsampl%c3%a9-3.jpg
. In my opinion this was a quick way to solve sanitation but should not be used because, apart from changing white spaces into dashes, it also codifies as an URL the string if non-ASCII characters are found.
On that moment an entry has already been added to the database with the URL encoded filename and a file is created on the server with the URL encoded name. So far, the file is saved. The problem comes when you want to retrieve the file: you put the URL generated on the browser (or just explore the gallery) and when accessing the server the request is sent to the server…then the server detects that the URL has codified elements, decodify them and try to access the file system…ops, file not found!A quick workaround would be:
Class : GalleryStorage_Driver_Base.php Function: upload_base64_image Original line: $filename = $filename ? sanitize_title_with_dashes($filename) : uniqid('nextgen-gallery'); New line: $filename = $filename ? urldecode(sanitize_title_with_dashes($filename)) : uniqid('nextgen-gallery');
With the change, the file will be saved with the correct name (original characters) and even using the URL encoded string will make it accessible. Of course this solves the problem accessing the file, but on the user interface the name of the file is still displaying the encoding and the database entry for that file has also the encoding.
This would be a nice and quick fix. Please let me know if I can provide you additional info in order to track and finally fix it.
Thanks,
Sergio
- The topic ‘Filename sanitation for non-ASCII encodings’ is closed to new replies.