views:

443

answers:

4

I've written some Ruby code to inspect ZIP-files as part of an internal company process. The way we usually launch this code is from a web browser. When you click to download the file, you select "open with" and specify the full path to a small batch file. This one-line batch file looks like this:

\\mathworks\public\Matthew_Simoneau\ruby-1.8.7-p72-i386-mswin32\bin\ruby.exe "%~dp0inspect.rb" %1

As far as I know, this technique is the only easy way to launch my Ruby code on a Windows machine which doesn't have Ruby installed, but does have access to the company internal filesystem.

I'm having a problem when the filename of the ZIP file contains an ampersand.

This works fine on IE and Chrome, where the above line gets "expanded" out to the following:

C:\WINNT\Profiles\matthew\Desktop>\\mathworks\public\Matthew_Simoneau\ruby-1.8.7-p72-i386-mswin32\bin\ruby.exe "\\mathworks\public\Matthew_Simoneau\sandbox\inspect\inspect.rb" "C:\WINNT\Profiles\matthew\Local Settings\Temporary Internet Files\Content.IE5\VNATJ3X0\park&park_paper_LMI_neuralN[1].zip"

On Firefox, however, everything after the ampersand in the filename gets dropped on the floor:

H:\>\\mathworks\public\Matthew_Simoneau\ruby-1.8.7-p72-i386-mswin32\bin\ruby.exe "\\mathworks\public\Matthew_Simoneau\sandbox\inspect\inspect.rb" C:\Temp\park

I've tried putting the %1 in quotes in the batch file, but that has no effect.

I suspect this is a bug in Firefox. I've searched the Firefox bug list, but didn't find anything.

Am I doing something wrong here? Is this a Firefox bug? If so, is there a way I can work around it? Is there a more robust way to launch my Ruby code from a web browser?

Update: I filed a bug report with Bugzilla@Mozilla, but there hasn't been a response yet.

A: 

Encode your ampersand for best results...

&

As in

C:\WINNT\Profiles\matthew\Desktop>\\mathworks\public\Matthew_Simoneau\ruby-1.8.7-p72-i386-mswin32\bin\ruby.exe "\\mathworks\public\Matthew_Simoneau\sandbox\inspect\inspect.rb" "C:\WINNT\Profiles\matthew\Local Settings\Temporary Internet Files\Content.IE5\VNATJ3X0\park&park_paper_LMI_neuralN[1].zip"
Sohnee
How? By the time I reach the batch file, the damage is already done.
Matthew Simoneau
+1  A: 

I've just tested something similar with Firefox 3.5.2 on Linux and it works well (i.e. shell script gets the correct path).

You should first try to use a script like that:

echo %1 > c:\temp\test.txt

(hope that's the right syntax, I didn't use cmd for a long time)

…and see if you get right path in that file. If the ampersand is stripped in that file too, and you're using the latest version of Firefox, that means you found bug specific to Windows platform and you should report it.

Michał Górny
I'm not sure it *is* a bug--I suspect it has something to do with UNC paths, which may be more limited than the local file system's allowed characters in filenames.
richardtallent
If the file is saved correctly by the browser, I don't think that could be the case.
Michał Górny
Michal, saving a file is altogether different from opening it again from the file system via a hyperlink. The former is not limited by the file URI syntax, the latter is.
richardtallent
Richard, the UNC path was a good suspect, so I mapped it to a drive and tested it out. Sadly, it didn't change anything.
Matthew Simoneau
I've just tested it with standard Firefox install on Windows XP and it strips the path on ampersand — so it is a bug.
Michał Górny
A: 

Use %24 for the & character. See the URL Encoding Table for other such problematic characters: http://webdesign.about.com/library/bl%5Furl%5Fencoding%5Ftable.htm

Rachel
How? By the time I reach the batch file, the damage is already done.
Matthew Simoneau
+1  A: 

Since you apparently have no control over the zip filenames, you could do the following in the Ruby code...

If the filename passed does not exist, look in the same folder for any file with the base passed filename followed by "&*.zip".

This will work for "park&park.zip" as long as there isn't also a zip file already in the folder named, say, "park&foo.zip".

If there is a real potential for filename collision (i.e., the zips aren't being cleaned off the user's machine and ampersands are common), the only other solution might be using a download manager plug-in in Firefox that has filename re-writing capability to fix any ampersands on the way down.

richardtallent
This a good idea for a workaround. Thanks!
Matthew Simoneau