ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 54285] Ant task exec arg value does not quote properly for MSWindows
Date Thu, 21 Feb 2013 05:19:12 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=54285

--- Comment #4 from Vincent Belaïche <vincent.b.1@hotmail.fr> ---
Hi,

After more thoughts I think that the code which I have provided is
over-complex, and there is a simpler solution as follows to double-quote a
string which is to replace all backslash and double quote respectively by \\
and \"

Examples:

a\b         is double quoted as "a\\b"
a"b         is double quoted as "a\"b"
a\\b        is double quoted as "a\\\\b"
"ab"        is double quoted as "\"ab\""

this means that if you call a command like this:

my-command "a\\b" "a\"b" "a\\\\b" "\"ab\"" 

then the argument passed to my-command are the following (one per line):

arg 1=a\b
arg 2=a"b
arg 4=a\\b
arg 5="ab"

One more nasty stuff is how to quote the percent sign. Imagine that you have an
environment variable TOTO that is unset, then

my-command "a%TOTO%b"

will pass argument 1 as follows

arg 1=a%TOTO%b

but if now TOTO is set to xxx, then the same

my-command "a%TOTO%b"

will pass

arg 1=axxxb

this is why, not to take any risks percent signs should also be quoted, and the
way to do that is to replace any % by ^% outside of the double-quotes so

a%TOTO%b is double quoted as "a"^%"TOTO"^%"b"
a%%%b    is double quoted as "a"^%^%^%"b"

I will prepare some updated code proposal for MSDosQuoter to reflex these new
thoughts.

-- 
You are receiving this mail because:
You are the assignee for the bug.
Mime
View raw message