🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.vm.bug
Article #712

Re: Can't launch attachments with "spaces" in file name

#712
From: Jeffrey J. Kosowsky
Date: Sun, 08 Feb 2004 04:14
113 lines
5665 bytes
Kevin Rodgers <ihs_4664@yahoo.com> writes:
> Jeffrey J. Kosowsky wrote:
>  > Kevin Rodgers <ihs_4664@yahoo.com> writes:
>  >>It might be that VM is using the file name that was cached in the MIME
>  >>layout, instead of the quoted file name.  What does this return on your
>  >>platform:
>  >>
>  >>	(shell-quote-argument
>  >>	 "c:/DOCUME~1/myname/LOCALS~1/Temp/FP&A 2004-2005 Capabilities.ppt")
>  >
>  > Returns:
>  >         "c:/DOCUME~1/myname/LOCALS~1/Temp/FP&A 2004-2005 Capabilities.ppt"
>  >
>  >>Also, what happens if you leave off the %f spec so that
>  >>vm-mime-display-external-generic adds the quoted name itself:
>  >>
>  >>	("application" "cmd /c")
>  >>	("audio" "cmd /c")
>  >>	("image" "cmd /c")
>  >>	("video" "cmd /c")
>  >
>  > No change...
>  >
>  > However, I have identified the *source* of the problem.
>  > According the the help message generated by "help cmd" in an XP shell,
>  > special characters like '&' need to be *directly* quoted. Specifically,
>  >         The special characters that require quotes are:
>  >              <space>
>  >              &()[]{}^=;!'+,`~
>  >
>  > In other words quoting the *entire* file name fails as follows:
>  >         cmd "FP&A 2004-2005 Capabilities.ppt"
>  > gives:
>  >         'FP' is not recognized as an internal or external command,
>  >         operable program or batch file.
>  >         'A.doc' is not recognized as an internal or external command,
>  >         operable program or batch file.
>  >
>  > Instead, you need to quote the *special* character itself as follows:
>  >         cmd FP"&"A 2004-2005 Capabilities.ppt
>  > which correctly opens the file.
> 
> Don't each of the spaces need to be quoted as well?  That would yield
> 
> 	cmd FP"&"A" "2004-2005" "Capabilities.ppt

Yes you are right :)

>  > So, to make this work, you need to quote directly all the special
>  > characters in the string represented by %f.
>  >
>  > Not sure how to do this best in elisp though... (Perl on the other
>  > hand would be very easy).
>  >
>  > At least, this seems to explain the problem!
> 
> Indeed.  What is system-type on your platform?  

windows-nt (which I believe is what you get on NT, Win2K, WinXP, etc)
Now according to the code for shell-quote-argument, in that case all
that happens is that \" is added to the beginning and end of the
string. This seems to be "wrong" according to the help screen on 'cmd'
under winxp.

Is this a "bug" in subr.el that should be reported to the general
emacs group or am I missing something here?


> lisp/subr.el defines shell-quote-argument, and its result depends on
> that variable.  But none of the alternatives use the quoting
> convention you describe.
> 
> If cmd is the shell you use for M-! and M-|, you can probably just redefine
> it:
> 
>       (defun cmd-quote-argument (argument)
>    "Quote ARGUMENT for a `cmd` command."
>    (let ((result "")
> 	(start 0)
> 	end)
>      (while (string-match "[][ &(){}^=;!'+,`~]" argument start)
>        (setq end (match-beginning 0)
> 	    result (concat result
> 			   (substring argument start end)
> 			   "\"" (substring argument end (1+ end)) "\"")
> 	    start (1+ end)))
>      (concat result (substring argument start))))
> 
> (defalias 'shell-quote-argument 'cmd-quote-argument)
> 
> -- 
> Kevin Rodgers


I did something just like the above (but also needed to add the
<space> as  you pointed out (and it works!!!)

I ended up adding the following:

(defun shell-quote-argument-winxp (argument)
  "Quote an argument for passing as argument to an inferior shell.
Special fixed version for WinXP (JJK)"
  (let 
          ((result "") (start 0) end)
        (while (string-match "[][&(){}^=;!'+,`~ ]" argument start)
            (setq end (match-beginning 0)
                  result (concat result (substring argument start end)
                                 "\"" (substring argument end (1+ end)) "\"")
                  start (1+ end)))
        (concat result (substring argument start))))

(if (eq system-type 'windows-nt)
        (defalias 'shell-quote-argument 'shell-quote-argument-winxp))
Technical Details
Message-ID: <m2ptcqw6lw.fsf@consult.pretender>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wn14feed!worldnet.att.net!199.45.49.37!cyclone1.gnilink.net!spamkiller2.gnilink.net!nwrdny03.gnilink.net.POSTED!9056c659!not-for-mail
References: <m2fzekj10g.fsf@consult.pretender> <400320B7.5060408@yahoo.com> <m2k73n2nrb.fsf@consult.pretender> <400D5599.10709@yahoo.com> <m2isj6m7a4.fsf@consult.pretender> <861xpth8a1.fsf@robf.deREMOVETHIS> <m2smi88qsy.fsf@consult.pretender> <86hdyoc6n9.fsf@robf.deREMOVETHIS> <m2y8rscb3z.fsf@consult.pretender> <4017E7FE.8040704@yahoo.com> <m21xpjvd3q.fsf@consult.pretender> <401FCD17.6010700@yahoo.com> <m2llnjn6bs.fsf@consult.pretender> <40241D13.8060908@yahoo.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f6829,6e83a1235cadfbbe
X-Google-Attributes: gidf6829,public
X-Google-ArrivalTime: 2004-02-07 20:14:05 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wn14feed!worldnet.att.net!199.45.49.37!cyclone1.gnilink.net!spamkiller2.gnilink.net!nwrdny03.gnilink.net.POSTED!9056c659!not-for-mail
Newsgroups: gnu.emacs.vm.bug
Subject: Re: Can't launch attachments with "spaces" in file name
References: <m2fzekj10g.fsf@consult.pretender> <400320B7.5060408@yahoo.com> <m2k73n2nrb.fsf@consult.pretender> <400D5599.10709@yahoo.com> <m2isj6m7a4.fsf@consult.pretender> <861xpth8a1.fsf@robf.deREMOVETHIS> <m2smi88qsy.fsf@consult.pretender> <86hdyoc6n9.fsf@robf.deREMOVETHIS> <m2y8rscb3z.fsf@consult.pretender> <4017E7FE.8040704@yahoo.com> <m21xpjvd3q.fsf@consult.pretender> <401FCD17.6010700@yahoo.com> <m2llnjn6bs.fsf@consult.pretender> <40241D13.8060908@yahoo.com>
From: kosowsky@consult.pretender (Jeffrey J. Kosowsky)
Message-ID: <m2ptcqw6lw.fsf@consult.pretender>
Lines: 113
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Date: Sun, 08 Feb 2004 04:14:05 GMT
NNTP-Posting-Host: 141.154.120.29
X-Complaints-To: abuse@verizon.net
X-Trace: nwrdny03.gnilink.net 1076213645 141.154.120.29 (Sat, 07 Feb 2004 23:14:05 EST)
NNTP-Posting-Date: Sat, 07 Feb 2004 23:14:05 EST