in reply to How to validate a directory string?

On most Unix systems any string that doesn't contain a null byte is a valid directory name, so that's what you could test (presumably that's m/\A[^\0]+\z/, not tested though.)

Replies are listed 'Best First'.
Re^2: How to validate a directory string?
by graff (Chancellor) on Sep 06, 2008 at 14:42 UTC
    There are good reasons to be a little more selective than that. For instance, allowing things that are not visible ascii characters is generally a bad idea, and including visible ascii characters that typically relate to "shell magic" (vertical bar, ampersand, the various brackets and quotes) can also lead to trouble. More and more, unix-heads are getting used to handling spaces in file names, but allowing TAB, CR and LF as well would be asking for trouble, IMHO.

    I'd be more inclined to something like

    /\A[^\x00-\x1f\x7f&*?|\\"'`<>{}()[\]]+\z/ # allows space and "safe" punctuation
    Of course, that still doesn't address the question of bytes outside the 7-bit ascii range, which includes the whole domain of utf8 wide characters. For that part of the issue, there isn't enough information in the OP to provide a basis for appropriate advice. (Would utf8 file names be allowable/sensible? What is expectable/possible regarding non-ascii content in the input strings?)