开发者

Validating file paths

We want to validate file paths, e.g. foo/bar, which the user can enter. Is it possible to create files with leading or trailing space on OS X or Linux, e.g. foo/ bar开发者_开发百科 /bazz?


In most file system you can use on linux, you are not allowed to use "/" and the NULL character in your filename. That's all :)


touch ' foo '

No problem on linux.


Quick experiment on OS X using the standard Mac OS HFS+ filesystem (the one that will be the default on most users machines). It is possible top create and mount more traditional Unix filesystems.

ls > " foo "
ls > "foo "
ls > " foo"
ls > foo


24 Aug 23:32  foo 
24 Aug 23:32 foo 
24 Aug 23:32  foo
24 Aug 23:32 foo

ls > "foo/ "
-bash: foo/ : Not a directory

So - leading and trailing space - yes. This ensures compatibility with classic Mac OS files. Use of / - no.

Now try

ls > Foo

and we see that 'foo' is updated. HFS is case insensitive by default (it can be enabled, but if you need to, probably better to use a completely alternative FS)

24 Aug 23:40 foo

This can obviously cause problems translating some standard Unix code to OS X if your code expects Foo and foo to both exist.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜