473,386 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Fix occasional escapes in the file path

VK
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.

Nov 7 '05 #1
3 2209

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

Nov 7 '05 #2
VK

Julian Turner wrote:
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.


Thanks for your response - indeed I was so concentrated on \n \f \t
cases that I missed the obvious \[normal char] case.
c:mydocumentsmypictures seems not resolvable w/o caller lookup and
study (getFolder.caller + a bunch of RegExp). Besides using deprecated
getFolder.caller it just gets too complicated and unreliable.

I guess I just put a check for the \n \f \t sweet trinity, as I don't
know any platform where new line, form feed or tab could be met in the
path name (?)

My abstract user is someone using 3rd party library, and my approach
(maybe questionnable) is that user has start to think only when the
computer cannot think for her anymore, not any earlier :-)

Nov 7 '05 #3
VK wrote:
I guess I just put a check for the \n \f \t sweet trinity, as I don't
know any platform where new line, form feed or tab could be met in the
path name (?)
You probably know only Microsoft Windows on an IBM-compatible PC.

It is a matter of the filesystem, not of the platform. Certain
characters are not allowed in filenames on FAT or NTFS filesystems
while they are allowed in other filesystems. For example, it is
possible to create a file named

test
1

on a ext2/ext3 filesystem:

$ touch 'test
1'

$ ls -l test*
-rw-r--r-- 1 ******* users 0 2005-11-08 00:28 test?1

(The `?' of course represents the non-printable newline character `\n'.)

A compatible ext2/ext3 filesystem driver provided, this can also be done
on a Windows or Mac system.
My abstract user is someone using 3rd party library, and my approach
(maybe questionnable) is that user has start to think only when the
computer cannot think for her anymore, not any earlier :-)


A JS programmer without a clue on JS is no JS programmer at all. Writing
a library that uses internal logic to counteract such incompetence on the
part of its user would be a recipe for disaster. More important, it cannot
be done since there is no difference between "c:abcde" and "c:\abcde" when
it comes to evaluation after which point the library would have to do
correction. Last but not least, there is no need for FAT/NTFS/UNC paths
on the Web as `file:' URIs serve their purpose.
PointedEars
Nov 7 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
6
by: Chris Anderson | last post by:
Anyone know of a fix (ideally) or an easy workaround to the problem of escape characters not working in regex replacement text? They just come out as literal text For example, you'd think that thi...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
1
by: BJörn Lindqvist | last post by:
Hello, I have some very serious trouble getting cookes to work. After a lot of work (urllib2 is severly underdocumented, arcane and overengineerd btw) I'm finally able to accept cookes from a...
2
by: David J Birnbaum | last post by:
Dear Python-list, I need to read a Unicode (utf-8) file that contains text like: I get my input and then process it with something like: When Python encounters the "\f" substring in an input...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
5
by: Eugene Anthony | last post by:
ds1.Tables.Rows.ItemArray.GetValue(0).ToString() contains the string path: images/5/Video1/qbert.flv if (File.Exists(ds1.Tables.Rows.ItemArray.GetValue(0).ToString())) { //code to execute } ...
3
by: John Nagle | last post by:
I have XML replies in a DOM which contain entity escapes, like "&". What's the proper way to replace them with the ordinary characters? Preferably something that will work in most browsers? I...
5
mikek12004
by: mikek12004 | last post by:
I was wondering why PHP escapes the single quotes in a GET or POST variable? is it just for display purposes or the single quot can mess up other things too? And it escapes just the single quote or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.