Filename sanitizing helper

1 view
Skip to first unread message

Mike Orr

unread,
Oct 9, 2009, 8:16:33 PM10/9/09
to pylons...@googlegroups.com
What would be a good filename-sanitizing helper for file uploads?
Currently I'm doing:

- Strip directory prefix.
- If filename contains "\\" (Windows directory prefix), strip through
the rightmost backslash.
- Convert all non-basic characters to "_". Basic characters are "A-Za-z0-9._-".

I'm not sure what to check the extension against. I don't want to
exclude any possibly-legitimate multimedia extensions, including
archaic or obscure formats. I'm not sure whether to allow multiple
dots. On the one hand, things like *.gif.exe are evil. On the other
hand, things like "myname.2009-10-22.utf8.txt" are not.

I looked in WebHelpers and did not find anything, so I think a
filename-sanitizing helper is needed.

--
Mike Orr <slugg...@gmail.com>

Randy Syring

unread,
Oct 10, 2009, 12:23:59 PM10/10/09
to pylons-devel
Reply all
Reply to author
Forward
0 new messages