[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] trunk r118196: Fix bug #18745 with invoking Windows batch
From: |
Eli Zaretskii |
Subject: |
[Emacs-diffs] trunk r118196: Fix bug #18745 with invoking Windows batch files with embedded whitespace. |
Date: |
Sat, 25 Oct 2014 09:13:54 +0000 |
User-agent: |
Bazaar (2.6b2) |
------------------------------------------------------------
revno: 118196
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/18745
author: Noam Postavsky <address@hidden>
committer: Eli Zaretskii <address@hidden>
branch nick: trunk
timestamp: Sat 2014-10-25 12:12:01 +0300
message:
Fix bug #18745 with invoking Windows batch files with embedded whitespace.
src/w32proc.c (create_child): If calling a quoted batch file,
pass NULL for exe.
nt/cmdproxy.c (batch_file_p): New function.
(spawn): If calling a quoted batch file pass NULL for progname.
test/automated/process-tests.el (process-test-quoted-batfile): New test.
modified:
nt/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1545
nt/cmdproxy.c cmdproxy.c-20091113204419-o5vbwnq5f7feedwu-1241
src/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1438
src/w32proc.c w32proc.c-20091113204419-o5vbwnq5f7feedwu-814
test/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-8588
test/automated/process-tests.el
sentineltests.el-20131108032506-2gjvnyk3qxe1ko3q-1
=== modified file 'nt/ChangeLog'
--- a/nt/ChangeLog 2014-10-20 19:59:41 +0000
+++ b/nt/ChangeLog 2014-10-25 09:12:01 +0000
@@ -1,3 +1,9 @@
+2014-10-22 Noam Postavsky <address@hidden>
+
+ * nt/cmdproxy.c (batch_file_p): New function.
+ (spawn): If calling a quoted batch file pass NULL for progname.
+ (Bug#18745)
+
2014-10-20 Glenn Morris <address@hidden>
* Merge in all changes up to 24.4 release.
=== modified file 'nt/cmdproxy.c'
--- a/nt/cmdproxy.c 2014-04-26 07:06:33 +0000
+++ b/nt/cmdproxy.c 2014-10-25 09:12:01 +0000
@@ -220,6 +220,28 @@
return o - buf;
}
+/* Return TRUE if PROGNAME is a batch file. */
+BOOL
+batch_file_p (const char *progname)
+{
+ const char *exts[] = {".bat", ".cmd"};
+ int n_exts = sizeof (exts) / sizeof (char *);
+ int i;
+
+ const char *ext = strrchr (progname, '.');
+
+ if (ext)
+ {
+ for (i = 0; i < n_exts; i++)
+ {
+ if (stricmp (ext, exts[i]) == 0)
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
/* Search for EXEC file in DIR. If EXEC does not have an extension,
DIR is searched for EXEC with the standard extensions appended. */
int
@@ -470,6 +492,13 @@
memset (&start, 0, sizeof (start));
start.cb = sizeof (start);
+ /* CreateProcess handles batch files as progname specially. This
+ special handling fails when both the batch file and arguments are
+ quoted. We pass NULL as progname to avoid the special
+ handling. */
+ if (progname != NULL && cmdline[0] == '"' && batch_file_p (progname))
+ progname = NULL;
+
if (CreateProcess (progname, cmdline, &sec_attrs, NULL, TRUE,
0, envblock, dir, &start, &child))
{
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog 2014-10-24 13:19:21 +0000
+++ b/src/ChangeLog 2014-10-25 09:12:01 +0000
@@ -1,3 +1,8 @@
+2014-10-25 Noam Postavsky <address@hidden>
+
+ * src/w32proc.c (create_child): If calling a quoted batch file,
+ pass NULL for exe. (Bug#18745)
+
2014-10-24 Eli Zaretskii <address@hidden>
* bidi.c (bidi_resolve_explicit, bidi_find_bracket_pairs)
=== modified file 'src/w32proc.c'
--- a/src/w32proc.c 2014-10-01 15:18:16 +0000
+++ b/src/w32proc.c 2014-10-25 09:12:01 +0000
@@ -1078,6 +1078,7 @@
DWORD flags;
char dir[ MAX_PATH ];
char *p;
+ const char *ext;
if (cp == NULL) emacs_abort ();
@@ -1116,6 +1117,15 @@
if (*p == '/')
*p = '\\';
+ /* CreateProcess handles batch files as exe specially. This special
+ handling fails when both the batch file and arguments are quoted.
+ We pass NULL as exe to avoid the special handling. */
+ if (exe && cmdline[0] == '"' &&
+ (ext = strrchr (exe, '.')) &&
+ (xstrcasecmp (ext, ".bat") == 0
+ || xstrcasecmp (ext, ".cmd") == 0))
+ exe = NULL;
+
flags = (!NILP (Vw32_start_process_share_console)
? CREATE_NEW_PROCESS_GROUP
: CREATE_NEW_CONSOLE);
=== modified file 'test/ChangeLog'
--- a/test/ChangeLog 2014-10-20 19:59:41 +0000
+++ b/test/ChangeLog 2014-10-25 09:12:01 +0000
@@ -1,3 +1,8 @@
+2014-10-22 Noam Postavsky <address@hidden>
+
+ * test/automated/process-tests.el (process-test-quoted-batfile):
+ New test.
+
2014-10-20 Glenn Morris <address@hidden>
* Merge in all changes up to 24.4 release.
=== modified file 'test/automated/process-tests.el'
--- a/test/automated/process-tests.el 2014-01-01 07:43:34 +0000
+++ b/test/automated/process-tests.el 2014-10-25 09:12:01 +0000
@@ -50,4 +50,26 @@
(should
(process-test-sentinel-wait-function-working-p (lambda () (sit-for 0.01
t)))))
+(when (eq system-type 'windows-nt)
+ (ert-deftest process-test-quoted-batfile ()
+ "Check that Emacs hides CreateProcess deficiency (bug#18745)."
+ (let (batfile)
+ (unwind-protect
+ (progn
+ ;; CreateProcess will fail when both the bat file and 1st
+ ;; argument are quoted, so include spaces in both of those
+ ;; to force quoting.
+ (setq batfile (make-temp-file "echo args" nil ".bat"))
+ (with-temp-file batfile
+ (insert "@echo arg1 = %1, arg2 = %2\n"))
+ (with-temp-buffer
+ (call-process batfile nil '(t t) t "x &y")
+ (should (string= (buffer-string) "arg1 = \"x &y\", arg2 = \n")))
+ (with-temp-buffer
+ (call-process-shell-command
+ (mapconcat #'shell-quote-argument (list batfile "x &y") " ")
+ nil '(t t) t)
+ (should (string= (buffer-string) "arg1 = \"x &y\", arg2 = \n"))))
+ (when batfile (delete-file batfile))))))
+
(provide 'process-tests)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] trunk r118196: Fix bug #18745 with invoking Windows batch files with embedded whitespace.,
Eli Zaretskii <=