Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: One true regexp for untainting windows filenames?

by jaldhar (Vicar)
on Jan 08, 2009 at 23:42 UTC ( [id://735047]=note: print w/replies, xml ) Need Help??


in reply to Re: One true regexp for untainting windows filenames?
in thread One true regexp for untainting windows filenames?

Thanks for the tip. I found slightly more understandable code in File::Spec which has resulted in the following regexps: for Unix...

qr{(\A (?: .* / (?: \.\.?\z )? )? [^/]* )}msx;
...and Windows (includes UNC paths)...
qr{(\A (?: [a-zA-Z]: | (?:\\\\\\\\|//)[^\\\\/]+[\\\\/][^\\\\/]+ )? (?:.*[\\/](?:\.\.?\Z(?!\n))?)? .* )}msx;

--
જલધર

Replies are listed 'Best First'.
Re^3: One true regexp for untainting windows filenames?
by ikegami (Patriarch) on Jan 09, 2009 at 05:33 UTC

    There is no a string that

    qr{(\A (?: .* / (?: \.\.?\z )? )? [^/]* )}msx

    won't match.

    It's wrong for two reasons.

    • "foo" gets "untainted" as "".
    • "x/xx\0xx"" is believed to be a valid file name, but it isn't.

    Valid unix paths and only valid unix paths match

    qr{^([\0]+)\z}

    (Although that doesn't mean there can ever be a file referenced by that path.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://735047]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-28 11:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found