Django

Code

Ticket #1355 (closed: duplicate)

Opened 3 years ago

Last modified 2 years ago

Internationalisation(charset) problems with FileField file names and core.db.backend.mysql

Reported by: little Assigned to: nobody
Milestone: Component: Core framework
Version: Keywords:
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description (Last modified by hugo)

The function django.utils.text.get_valid_filename() is not friendly for non-latin file-names

    s = s.strip().replace(' ', '_')
    return re.sub(r'[^-A-Za-z0-9_.]', '', s)

truncates file name to underscores only: "__________.txt" for example.

Let it retun a Unicode object of string s

    return unicode(s,'utf8')

Or make it possible to overload this function to end-programmer.

Attachments

Change History

02/14/06 09:08:14 changed by hugo

  • description changed.

The problem here: we can't assume anything about the filesystem of the server beside the fact that it is possible to use us-ascii in filenames. So utf-8 won't be an option - it might produce unreadable filenames. And since there are several places that function like / and ., we can't just accept any char we want, or we would open up for filesystem traversal hackery.

One way would be to just turn non-ascii chars into a uXXXX form, so that at least the filename isn't all dashes.

I move the database stuff into it's own ticket, as that isn't i18n related, but more database backend related.

02/14/06 15:42:28 changed by little

Another good way to name files is to give them [database id].ext names for example 12345.txt 34567.doc and so on...

Files like numbers are more better than underscores, any way.

05/24/06 09:31:29 changed by hugo

  • owner changed from hugo to adrian.
  • component changed from Internationalization to Core framework.

11/29/06 01:48:15 changed by limodou@gmail.com

Yeah, I also encounter this problem. And I hope how to use i18n filename should determined by ender user but not automatically processed. Or we can set some flag in save_FIELD_file() method, just like:

object.save_FIELD_file(i18n_filename, content, safety=True)

This will use get_valid_filename to deal with filename, and if user invoke:

object.save_FIELD_file(i18n_filename, content, safety=False)

This will not use get_valid_filename. Parameter safety can be default True in order to keep compatibility with the old function.

01/21/07 22:01:22 changed by SmileyChris

  • stage changed from Unreviewed to Accepted.

Accepted. Seems obvious something needs to change.

09/16/07 10:22:38 changed by ubernostrum

  • status changed from new to closed.
  • resolution set to duplicate.

Closing in favor of #3119, which has a patch.


Add/Change #1355 (Internationalisation(charset) problems with FileField file names and core.db.backend.mysql)




Change Properties
Action