November Happy Hour will be moved to Thursday December 5th.

File upload - regex for illegal characters in path

Vote:
 

We have been asked to restrict filenames for uploaded files in the file manager to files containing only alphanumerics, underscores and hyphens. In order to do this, we have been using a modified version of the regular expression given for "illegalCharactersRegex" at http://world.episerver.com/Documentation/Items/Tech-Notes/EPiServer-CMS-6/EPiServer-CMS-6-R2/Configuration---episerver-Section/.

I've modified this regex by adding a check for characters other than alphanumerics, underscores, hyphens, a period (for extensions), and a slash (for directory/filename separators) as follows:

illegalCharactersRegex="[^A-Za-z0-9\-_\./]|^COM[0-9]([/\.]|$)|^LPT[0-9]([/\.]|$)|^PRN([/\.]|$)|^CLOCK\$([/\.]|$)|^AUX([/\.]|$)|^NUL([/\.]|$)|^CON([/\.]|$)"

However, this regex is matching even when I attempt to upload a file whose name is simply "test".

I've tested by setting the illegalCharactersRegex to test for specific individual characters and I've found that in particular, it matches on a tilde (~) when uploading a file with the same name as one already in the file manager, but not when uploading a file with a completely new name, so clearly there is some kind of transformation being carried out on the file/directory name somewhere along the line.

I have two questions here:

1. What is the exact format of the file or directory name that is tested against illegalCharactersRegex? Are files and directories tested together as a single path, or as different components of the path?

2. What is being tested other than the file or directory name? Where is the tilde coming from, and what else is being passed to the regex that I don't know about?

#75307
Sep 24, 2013 17:44
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.