This question about Topic Markup Language and applications: Answered
A forced link with '#' character generates inproper HTML
If I create a forced link using the
[[][]]
syntax with a '#' character in the URL portion, I get invalid character encoding.
For example, with this construct
[[file://///server/share/file #6][Link to file #6]]
the generated URL is:
file://///server/share/file%20#6
and not
file://///server/share/file%20%236
I'm unsure how I should expect Foswiki to encode the URL portion... I note that it encodes spaces with '%20'. Should I expect it to encode '#' with '%23'?
If I can't expect Foswiki to encode this correctly then I have a problem because these forced links are created with an
EasyMacroPlugin macro of this nature:
%REGISTERMACRO{"AFILE" format="[[file://///server/share/$file][$file]]" warn="off" param="file" file="somefile" }%
and the user is expected to cut-and-paste the filename into the macro usage like this
%AFILE{"file #6"}%
Suggestions?
EDIT: I notice that something like this
[[file://///server/share/file #6 & #7][Link to file #6 & #7]]
doesn't cause the '&' doesn't get encoded, which probably means I'm just lucky and probably need to use
!
, but every attempt to use it fails spectacularly. Help needed.
--
BigBaaadBob - 10 Dec 2009
Hi Bob, I'm going to guess that the # is not encoded because it's valid in a URL as an anchor. Probably the same thing for the & as it would be used to add parameters to the URL. Other than that I don't have any suggestions. Maybe explicit links of the file:// type should be encoded differently from html:// style links. Ideally what would the
file:// url look like? #?space all encoded, or all left literal or?
Some of this may depend upon the browser version. In locally testing IE 6 vs. Firefox, IE6 works only when the # is not encoded, and Firefox only works when the # is encoded as %23.
RFC 1738 says that
"The character "#" is unsafe and should always be encoded because it is used in World Wide Web and in other systems to delimit a URL from a fragment/anchor identifier that might follow it." so this seems to say that IE is not correct.
Digging around there is also
This article on mozillazine.org that discusses these links - Firefox will always block them by default to prevent certain attacks.
I probably need some suggestions on how to deal with this.
--
GeorgeClark - 11 Dec 2009
Hi George:
Let's ignore the Firefox
file:
URL thing because I've worked around that.
Considering this path:
* Set FILE1 = dir\thing #1 & 2.doc
This seems to work:
[[%ENCODE{"file://///server/share/%FILE1%"}%][%FILE1%]]
on both FF and IE in the sense that the URL will actually open the referenced
FILE1
.
I completely fail when trying to translate that into something that the
EasyMacroPlugin understands, probably because I can't get the quoting straight. For example:
%REGISTERMACRO{"AFILE" format="[[%ENCODE{file://///server/share/$file}%][$file]]" warn="off" param="file" file="somefile" }%
is a fail. I'm sure it is simple. Just not for me.
--
BigBaaadBob - 14 Dec 2009
OK, I figured out my quoting issues. This works:
%REGISTERMACRO{"AFILE" format="[[$percntENCODE{\"file://///server/share/$file\"}$percnt][$file]]" warn="off" param="file" file="somefile" }%