UseModWiki | WikiSuggestions | RecentChanges | Preferences

Spaces in URLs

We have a share that everyone uses. I can use file:// links in Wiki pages, but only if there are no spaces in the filename. Typically, there are, and it's infeasible to ask teh whole organisation to stop doing that.

So, I'd like a way of putting spaces in URLs - perhaps by enclosing the URL in spaces, or in <URL: > ?

don't web browsers solve this by changing spaces to %20?

Yes, but that's unfriendly to the user - asking them to type %20 etc. However, after much pain with $URLPattern and regexps, I couldn't get anything like my suggestion above to work. I made a change to use %20 etc and decoding the URL in &UrlLink? and &StoreBracketUrl? - and then discovered this seems to work anyway as standard, even though I thought I checked that first. Strange.

You could try substituting + marks for the spaces ... http://www.google.com/q=words+with+spaces. Not as tedious as writing %20.

We do this also. Everyone has the same drive mappings and uses IE on our LAN, and we like to link to MS Office documents. To get it to work we use the %20 thing. The weird thing I've encountered was that IE doesn't like %20 (or any uri encoded strings) in file:// links. Originally, a link like this: file://Drive/Vol1/the%20file.doc wouldn't work. After clicking on the link, it would show up, as typed, with the %20 in the address bar, and IE would look for a file with a literal %20 in it.

To fix it I did this (I guess this is what you're doing... <?>) :

 use URI::Escape;

 ... in &UrlLink?

  if ($NetworkFile && $name =~ m|^file:|) {
    # Only do remote file:// links. No file:///c|/windows.	
    if ($name =~ m|^file://[^/]|) {

      # return ("<a href=\"$name\">$name</a>", $punct); 	 ## Old line.

      ## Update to make file://image.gif links work
      if ($useImage && ($name =~ /^file:.+\.$ImageExtensions$/)) {	  	  	  
          return ("<img src=\"". uri_unescape($name) ."\">", $punct);		  

      ## Update of the Old line. 
      return ( "<a href=\"". uri_unescape($name) ."\">$name</a>", $punct);

  ... in &StoreBracketUrl?

  if ($url =~ m|^file://[^/]|) {
      return &StoreRaw("<a href=\"". uri_unescape($url) ."\">[$text]</a>");

So this is using %20 to keep the string together, and then it is unescaping() the string in the HTML source. Images also work properly. I'd rather be able to type spaces...

UseModWiki | WikiSuggestions | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited July 6, 2005 6:26 pm by RichardP (diff)