Search code examples
rubyfirefoxbatch-fileescapingampersand

How do I make Firefox open a file with an ampersand in the filename?


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.


Solution

  • 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.