[PATCH 2/2] [cmd] Fix tilda parameter expansion when arg is empty

Ann and Jason Edmeades jason at edmeades.me.uk
Sun Jun 2 16:57:00 CDT 2013


When %~i expands and the parameter itself is empty, ensure
the parameter expansion occurs to an empty string.

[Fixes bug 33638]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20130602/0a0b488a/attachment.html>
-------------- next part --------------
From 9f223642bcbe486687171a082a0a482aaf84e8be Mon Sep 17 00:00:00 2001
From: Jason Edmeades <jason at edmeades.me.uk>
Date: Sun, 2 Jun 2013 21:29:58 +0100
Subject: [PATCH 2/2] [cmd] Fix tilda parameter expansion when arg is empty

When %~i expands and the parameter itself is empty, ensure
the parameter expansion occurs to an empty string.

[Fixes bug 33638]
---
 programs/cmd/batch.c                     |   12 +++++++-----
 programs/cmd/tests/test_builtins.cmd     |    1 +
 programs/cmd/tests/test_builtins.cmd.exp |    1 +
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index 09081f4..294a153 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -514,11 +514,13 @@ void WCMD_HandleTildaModifiers(WCHAR **start, BOOL atExecute)
   /* After this, we need full information on the file,
     which is valid not to exist.  */
   if (!skipFileParsing) {
-    if (GetFullPathNameW(outputparam, MAX_PATH, fullfilename, NULL) == 0)
-      return;
-
-    exists = GetFileAttributesExW(fullfilename, GetFileExInfoStandard,
-                                  &fileInfo);
+    if (GetFullPathNameW(outputparam, MAX_PATH, fullfilename, NULL) == 0) {
+      exists = FALSE;
+      fullfilename[0] = 0x00;
+    } else {
+      exists = GetFileAttributesExW(fullfilename, GetFileExInfoStandard,
+                                    &fileInfo);
+    }
 
     /* 2. Handle 'a' : Output attributes (File doesn't have to exist) */
     if (memchrW(firstModifier, 'a', modifierLen) != NULL) {
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index f3aa1a9..45617cf 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -363,6 +363,7 @@ for %%i in ("d e" f) do echo %%~dpi
 for %%i in ("g h" i) do echo %%~sdi
 for %%i in ("g h" i) do echo %%~dsi
 for %%i in ("j k" l.eh) do echo '%%~xsi'
+for %%i in ("") do echo '%%~i,%%~fi,%%~di,%%~pi,%%~ni,%%~xi,%%~si,%%~ai,%%~ti,%%~zi'
 
 echo --- in parameters
 for %%i in ("A B" C) do call :echoFun %%i
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index dd6ccb5..99ed738 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -319,6 +319,7 @@ N
 @drive@
 ''
 '.eh'
+',,,,,,,,,'
 --- in parameters
 "A B"
 C
-- 
1.7.9.5


More information about the wine-patches mailing list