JZ wrote:
$command="myapp.exe -P d:\mydir\mySubDir";
echo "<td><a href=\"javascript:LaunchApp('$command')\">blah</a></td>";
This works fine.
Only for a bizarre definition of 'fine'. It might give the
impression of working in a handful of situations, but it
fails in a bucketload and it's by no means correct.
Strictly speaking, the resulting construct is not HTML
because, on two accounts, the href value is not a URI.
First, the value contains characters which are disallowed in
URIs: spaces and backslashes, the percent-encodings of
which are %20 and %5C respectively. Second, the javascript
scheme has not been registered, and so even if you were to
percent-encode the disallowed characters, the construct
would still violate the HTML spec.
See c.i.w.a.html for discussions on the more practical
downsides of the javascript pseudo-protocol in hrefs, and on
why you should use event handlers instead.
But when 'mySubDir' becomes 'my Sub Dir' myapp
requires quotes:
myapp.exe -P "d:\mydir\my Sub Dir"
Inside a double-quoted attribute value, a double-quote can
be represented by the entity reference " or the
character references " and ". Double-quotes are
disallowed in URIs, however, so they must be percent-encoded
with %22.
So I tried (along with several variations):
echo "<td><a href=\"javascript:LaunchApp('myapp.exe -P "d:\mydir\my
Sub Dir"')\">blah</a></td>";
echo "<td><a href=\"javascript:LaunchApp('myapp.exe -P \"d:\mydir\my
Sub Dir\"')\">blah</a></td>";
Whatever I tried my string ends after -P
In the first example, yes; you get a parse error because the
double-quote after the '-P' ends the first string of the
echo. For a double-quote to appear in a double-quoted
string, you must escape it with a backslash.
If you look closely, you'll see the string in the second
example is exactly what you asked for: The escaped double-
quote after the '-P' closes the href attribute, and by dint
of reasonable error recovery, everything up to the
next '>' is ignored. Proof: View the source.
Reasonableness isn't a requirement of the spec however.
Slainte! & HAGW!
--
Jock