Gossamer Forum
Home : General : Perl Programming :

filenames

Quote Reply
filenames
I have a database of users, where the username is restricted to 50 characters, but that's about the only restriction there is on the username. Usernames can also be email addresses (yes, this is Links SQL with users imported from Links 2).

Now I want to build a file or directory for each user, and the file/directory will have the name username.html (or so). Obviously, in order for this to be secure, I have to take care that the file/directory is only built if the username fulfills certain criteria.

I am using the following regexes to strip out everything but alphanumeric characters, dots, @'s and leading dots.
Code:
$username =~ s,[^\w\d\.\@],,g;
$username =~ s,^\.+,,g;

Is this enough? Also, would usernames that pass through the above validation necessary make good filenames/directories on 'any' OS? They seem to be OK on Linux, but what about Windows? Anything else I should take care of?

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] filenames In reply to
Do you really want to leave spaces in? Do you want Windows 95/DOS support i.e., < 8 character file names?

- wil
Quote Reply
Re: [Wil] filenames In reply to
It's for a Links SQL plugin, which I assume does not run under Windows 95/DOS....

Spaces are not left in.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] filenames In reply to
OK. Just trying to assist in giving you some possible scenarios.

Good luck!

- wil
Quote Reply
Re: [Wil] filenames In reply to
I didn't mean to be rude or anything, I was just short in my answer. Smile

About the spaces: it looks like there is a space after \., but there actually isn't, so spaces are stripped out.

Ivan
-----
Iyengar Yoga Resources / GT Plugins