Problem/Motivation

When upload file with a long name (name does not contain spaces) via the file widget then the file name displayed in a single line and page markup looks like broken (al least a horizontal scroll shows up):
Before

Proposed resolution

Add the wbr tag after each underscores in the file name:
After

User interface changes

Add the Break row checkbox to the field manage page:
Setting

Comments

chmez created an issue. See original summary.

ohorbatiuk’s picture

Assigned: ohorbatiuk » Unassigned
Status: Active » Needs review
StatusFileSize
new3.26 KB
chi’s picture

This won't work if words in a file name are separated by dashes or any other characters. I think it would be much easier to limit the width using CSS max-width or text-overflow properties.

ohorbatiuk’s picture

StatusFileSize
new690.06 KB

I do not think showing only part of the file name is a good idea. Also, in my case need to display the full filename.

When words are separated by dashes or spaces then this patch is not needed because a bug is not reproducible:
Dashes

ohorbatiuk’s picture

Issue summary: View changes
tripurari’s picture

@chmez, Issue is still reproducible on Drupal 7 using underscore and same is not reproducible by using spaces in the uploaded file without applying Patch as per #4. Please find the Screenshot for your reference.

tripurari’s picture

StatusFileSize
new106.98 KB
tripurari’s picture

StatusFileSize
new106.98 KB
new101.92 KB
tripurari’s picture

Please ignore Comment was trying to add Organization name by mistake comment was added.

charles belov’s picture

I don't believe we can assume the file name will contain specific characters such as an underscore. A file name such as QwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwertyQwerty.pdf is perfectly legitimate and would not be rescued by this patch.

I suggest just adding the style:

word-break: break-all;

charles belov’s picture

Status: Needs review » Needs work
ohorbatiuk’s picture

Status: Needs work » Needs review

@charles-belov, I don't agree with you because most of the software suggests using human-readable file names (words separated by spaces) which converts by Drupal (replace spaces by underscores).

charles belov’s picture

We have no control over what file names people upload. There is nothing preventing them from uploading file names that are just a long random string of alphanumeric characters. Even if that's not a best practice, there is no reason I can think of to create a solution that breaks in such cases, when a solution that works in all cases exists.

chi’s picture

Agree #13. The way users name their files is beyond our control.

ohorbatiuk’s picture

StatusFileSize
new3.29 KB
poker10’s picture

Thanks for reporting and working on this @chmez!

I think that the solution which will work with all possible filenames would be better, as mentioned in #13. What are the cons of using word-break: break-all;? It could be even less "intrusive" change in comparision with adding a new checkbox to the file field configuration.

human-readable file names (words separated by spaces) which converts by Drupal (replace spaces by underscores).

Drupal 7 does not have such conversion in the core - do you meant the Transliteration module? We cannot assume that sites will have this module installed. If you upload a file with spaces on vanilla D7 core to the file field, then nothing is changed and the filename is kept as it is.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.