VK wrote:
On Windows platforms path separator "\" collides with the script escape
sign "\"
Obvious and old way to prevent it is to double backslashes: "\\"
But I'm curious if there is a reliable way to *restore* the right path
is user occasionally forgets to double some slash? Naturally nothing we
can do in a case like:
getFolder("c:\docs\new\") because it will lead to the syntacs error
long before to arrive to getFolder function.
But in case like getFolder("c:\docs\new")
getFolder will get the path but it will be corrupted.
Some amateur thoughts:-
When you say the "user" occasionally forgets, who is the user. Your
example suggests that the user is in fact writing Javascript, because
escaping back slash characters is only needed when writing a string
literal. If so, is that issue is more of a coding quality control
issue.
If the path checking is done at code writing stage, then if the user
types 'getFolder("c:\docs\new")' then it might be feasible to read the
source code and look for instances of '\d' and make an assumption that
'\\d' was intended, but '\n' will be an ambiguous case.
If the path checking is done at run-time, then the path will already be
'c:docs
ew'
which might be easy to guess, but what about
c:mydocumentsmypictures - there is no way to make a guess as to where
the diving lines were intended to be without some knowledge of the
likely paths that may be inputted.
If your "user" is typing backslashes into an INPUT text field or
TEXTAREA, or the file path is to be an attribute value in HTML markup,
then your user does not need to escape the backslash at all.
Julian