?
avatar sm0rgm
sm0rgm
9 Dec 2018

Steps to reproduce the issue

  1. Go to Content -> Articles -> New article
  2. Upload an image file using the image tool in the toolbar, for example a file named abc-def-geh_1.jpg.
  3. Check the article source code and verify that the file name is intact, i.e. abc-def-geh_1.jpg.
  4. Now upload a file named for example abc-def-geh_2.jpg using drag and drop into the article.
  5. Check the article source code and see that the file name of the uploaded file has been stripped from it's hyphens.
    screen shot 2018-12-09 at 08 17 37

Expected result

The filename should remain intact with hyphens when uploading through drag and drop.

Actual result

Image files uploaded through drag and drop gets stripped of it's hyphens.

System information (as much as possible)

Joomla 3.9.1. Editor is TinyMCE. Content and backend language is Swedish.

Additional comments

Missing hyphens in file names is harmful to SEO as Google reads hyphens as spaces. I.e. a file named a-nice-glass-of-beer.jpg is read by Google as "a nice glass of beer.jpg" and can be interpreted correctly. When the hyphens are missing Google will have a hard time understanding what aniceglassofbeer.jpg is.

avatar sm0rgm sm0rgm - open - 9 Dec 2018
avatar joomla-cms-bot joomla-cms-bot - labeled - 9 Dec 2018
avatar infograf768
infograf768 - comment - 10 Dec 2018

I am afraid this does not depend on Joomla but on TinyMCE itself.
@dgrammatiko ?

avatar dgrammatiko
dgrammatiko - comment - 10 Dec 2018

@infograf768 has nothing to do with tinyMCE or the drag and drop script, it's coming from this line: https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_media/controllers/file.json.php#L88

avatar infograf768
infograf768 - comment - 10 Dec 2018

@dgrammatiko
Weird. Why would we replace hyphens by nothing in that json file and not when we upload through "normal" com_media upload?

Even better, we replace spaces by hyphens in "normal" upload...

avatar infograf768
infograf768 - comment - 10 Dec 2018

In any case, changing that code to
$safeFileName = preg_replace(array("/[\\s]/", '/[^a-zA-Z0-9_\-]/'), array('_', ''), $fileparts['filename']) . '.' . $tempExt;
looks like solving the specific issue.

avatar infograf768
infograf768 - comment - 10 Dec 2018

@dgrammatiko
It looks you are the one who did not add the hyphen in this preg_replace
see https://github.com/joomla/joomla-cms/pull/7435/files#diff-e5953bc3eadad37980d677840c9d4f6dR88
years ago . ROTFLOL

May I make patch?

avatar sm0rgm
sm0rgm - comment - 10 Dec 2018

@infograf768: I can verify that the suggested code change resolves the issue.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/23249.

avatar infograf768
infograf768 - comment - 10 Dec 2018

It does, but remains to modify some stuff in the "normal" upload.
I explain:

  1. the name of a file should not contain any period . before the extension.
    (real original name of these files are of the type: Screen Shot 2018-12-09 at 07.43.58.png on my Mac)
    This is nicely taken care of when drag and drop as periods are replaced by nothing (after adding the hyphen in the code above).
    Screen_Shot_2018-12-09_at_075108.png
    BUT not in normal upload where I get:
    Screen-Shot-2018-12-10-at-09.29.49.png

  2. Also, spaces are replaced by hyphens in one case and by underscores in the other.
    I think this should be normalized.

Will try to solve these issues, making sure that the files can also be deleted by com_media.

avatar infograf768
infograf768 - comment - 10 Dec 2018

Please test #23259

Closing as we have a patch

avatar Quy Quy - change - 10 Dec 2018
Status New Closed
Closed_Date 0000-00-00 00:00:00 2018-12-10 19:09:18
Closed_By Quy
avatar joomla-cms-bot joomla-cms-bot - change - 10 Dec 2018
Closed_By Quy joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 10 Dec 2018
avatar joomla-cms-bot
joomla-cms-bot - comment - 10 Dec 2018

Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/23249

Add a Comment

Login with GitHub to post a comment