Platform-specific file path delimiters
Mark Waddingham
mark at livecode.com
Wed Sep 23 13:32:11 EDT 2015
On 2015-09-23 18:53, Richard Gaskin wrote:
> A regression with UNC paths was recently fixed:
> <http://quality.runrev.com/show_bug.cgi?id=15814>
>
> Most interesting to me there is that it allows the use of the
> Windows-specific "\" as a file path delimiter.
This is very much a case of 'unintended consequences' or 'just because
you can do something, it doesn't mean you should' (and why maintaining,
updating, evolving the engine whilst retaining backwards compatibility
can be very very difficult at times).
> I didn't know OS-specific delimiters could be used.
That's good - you shouldn't use them - it would probably be best that
everyone forgets that you can, and try to ensure you don't use them
anywhere in new applications :)
> Can I use backslash in all file I/O calls in Windows? What are the
> rules that would let me know when I can can use platform-specific file
> path delimiters, and when I need to use the customary Unix-style "/"
> as we normally see on all platforms?
The fact they ever worked was a side-effect of the fact that Win32 API
calls are quite tolerant of file path separators. Both '/' and '\' are
reserved in Windows filenames, and higher-level APIs (which the engine
previously used) can happily accept both.
As UNIX systems happily accept '\' as a filename (leaf) character, the
engine never did any higher-level validation / processing / checking of
such things (as things like foo/bar\foo is a perfectly valid path on
UNIX). This meant that when the engine was ported to Windows initially,
such things would pass straight through and thus (in many cases) work
fine - even though the interpretation of such a thing (with the idea
that / becomes \ on Windows) is actually quite different between Windows
and non-Windows in this setting.
Over time, we've tightened up the way path manipulation works (in
particular, the engine now explicitly turns a relative path into an
absolute path in a platform-independent fashion to ensure consistency)
and unfortunately this work broke this long standing ability. We have
now (through fixing this bug) preserved this functionality because there
is a fair bit of code out there which depends on it.
However, as I said above, don't use OS specific separators in your paths
in new apps / code. Always use '/' and let the engine do the right thing
- you'll be better off that way :)
Mark.
--
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps
More information about the use-livecode
mailing list