https://bugs.winehq.org/show_bug.cgi?id=44373
Bug ID: 44373 Summary: cmd's %0 path variables (e.g. %~dp0) don't match those of Windows (w.r.t. case and quoting) Product: Wine Version: 3.0-rc6 Hardware: x86 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: cmd Assignee: wine-bugs@winehq.org Reporter: ryan.prichard@gmail.com Distribution: ---
I'm filing this issue at Fabian Maurer's suggestion, after filing https://bugs.winehq.org/show_bug.cgi?id=44369.
When %0 starts with a quote character, Windows tends to evaluate the %0 path variables (%~d0, %~p0, ...) strangely. I think the Wine behavior makes more sense, but it could also make sense to match Windows bug-for-bug.
Test program (you might have to fix up the C:\bin for your machine):
C:>mkdir Bin
C:\Bin\ShowArg0.Cmd:
@echo [%0] -------------------- [%~d0] [%~p0] [%~n0] [%~x0]
C:\Bin\RunScript.Cmd
@echo off setlocal set PATH=C:\bin;%PATH% cd \ echo --- Wine and Windows roughly do the same thing. call showarg0 call SHOWARG0 call showarg0.cmd call SHOWARG0.CMD call C:\bin\showarg0 call C:\bin\showarg0.cmd call c:\bin\showarg0.CMD call showarg0".cmd" call showarg0."cmd" call showarg0.c"md" call s"ho"warg0.cmd call s"ho"warg0 call "C:\bin\showarg0.cmd" call "c:\bin\showarg0.CMD" echo --- Wine and Windows diverge here. call "showarg0" call "SHOWARG0" call "showarg0.cmd" call "SHOWARG0.CMD" call "showarg0".cmd call "sho"warg0.cmd call "sho"warg0 call "C":\bin\showarg0.cmd call "C:"\bin\showarg0.cmd call "C:"bin\showarg0.cmd call "c:"bin\showarg0.CMD call "C:\bin\showarg0"
(I edited the script output to align the columns.)
Windows behavior (tested on XP and Win10.0.16299.125):
C:\Bin>RunScript --- Aside from case, Wine and Windows roughly do the same thing. --- ... Using c:\bin in PATH [showarg0] ----------------- [c:] [\Bin] [ShowArg0] [.Cmd] [SHOWARG0] ----------------- [c:] [\Bin] [ShowArg0] [.Cmd] --- ... Using C:\bin in PATH [showarg0] ----------------- [C:] [\Bin] [ShowArg0] [.Cmd] [SHOWARG0] ----------------- [C:] [\Bin] [ShowArg0] [.Cmd] [showarg0.cmd] ------------- [C:] [\Bin] [ShowArg0] [.Cmd] [SHOWARG0.CMD] ------------- [C:] [\Bin] [ShowArg0] [.Cmd] [C:\bin\showarg0] ---------- [C:] [\Bin] [ShowArg0] [.Cmd] [C:\bin\showarg0.cmd] ------ [C:] [\Bin] [ShowArg0] [.Cmd] [c:\bin\showarg0.CMD] ------ [c:] [\Bin] [ShowArg0] [.Cmd] [showarg0".cmd"] ----------- [C:] [\Bin] [ShowArg0] [.Cmd] [showarg0."cmd"] ----------- [C:] [\Bin] [ShowArg0] [.Cmd] [showarg0.c"md"] ----------- [C:] [\Bin] [ShowArg0] [.Cmd] [s"ho"warg0.cmd] ----------- [C:] [\Bin] [ShowArg0] [.Cmd] [s"ho"warg0] --------------- [C:] [\Bin] [ShowArg0] [.Cmd] ["C:\bin\showarg0.cmd"] ---- [C:] [\Bin] [ShowArg0] [.Cmd] ["c:\bin\showarg0.CMD"] ---- [c:] [\Bin] [ShowArg0] [.Cmd] --- Wine and Windows diverge here. ["showarg0"] --------------- [C:] [] [showarg0] [] ["SHOWARG0"] --------------- [C:] [] [SHOWARG0] [] ["showarg0.cmd"] ----------- [C:] [] [showarg0] [.cmd] ["SHOWARG0.CMD"] ----------- [C:] [] [SHOWARG0] [.CMD] ["showarg0".cmd] ----------- [C:] [] [showarg0"] [.cmd] ["sho"warg0.cmd] ----------- [C:] [] [sho"warg0] [.cmd] ["sho"warg0] --------------- [C:] [] [sho"warg0] [] ["C":\bin\showarg0.cmd] ---- [C:] [\C":\bin] [showarg0] [.cmd] ["C:"\bin\showarg0.cmd] ---- [C:] ["\bin] [showarg0] [.cmd] ["C:"bin\showarg0.cmd] ---- [C:] ["bin] [showarg0] [.cmd] ["c:"bin\showarg0.CMD] ---- [c:] ["bin] [showarg0] [.CMD] ["C:\bin\showarg0"] -------- [C:] [\Bin] [showarg0] []
Behavior on wine-3.0-rc6:
C:\Bin>RunScript --- Aside from case, Wine and Windows roughly do the same thing. --- ... Using c:\bin in PATH [showarg0] ----------------- [c:] [\bin] [showarg0] [.CMD] [SHOWARG0] ----------------- [c:] [\bin] [SHOWARG0] [.CMD] --- ... Using C:\bin in PATH [showarg0] ----------------- [C:] [\bin] [showarg0] [.CMD] [SHOWARG0] ----------------- [C:] [\bin] [SHOWARG0] [.CMD] [showarg0.cmd] ------------- [C:] [\bin] [showarg0] [.cmd] [SHOWARG0.CMD] ------------- [C:] [\bin] [SHOWARG0] [.CMD] [C:\bin\showarg0] ---------- [C:] [\bin] [showarg0] [.CMD] [C:\bin\showarg0.cmd] ------ [C:] [\bin] [showarg0] [.cmd] [c:\bin\showarg0.CMD] ------ [c:] [\bin] [showarg0] [.CMD] [showarg0".cmd"] ----------- [C:] [\bin] [showarg0] [.cmd] [showarg0."cmd"] ----------- [C:] [\bin] [showarg0] [.cmd] [showarg0.c"md"] ----------- [C:] [\bin] [showarg0] [.cmd] [s"ho"warg0.cmd] ----------- [C:] [\bin] [showarg0] [.cmd] [s"ho"warg0] --------------- [C:] [\bin] [showarg0] [.CMD] ["C:\bin\showarg0.cmd"] ---- [C:] [\bin] [showarg0] [.cmd] ["c:\bin\showarg0.CMD"] ---- [c:] [\bin] [showarg0] [.CMD] --- Wine and Windows diverge here. ["showarg0"] --------------- [C:] [\bin] [showarg0] [.CMD] ["SHOWARG0"] --------------- [C:] [\bin] [SHOWARG0] [.CMD] ["showarg0.cmd"] ----------- [C:] [\bin] [showarg0] [.cmd] ["SHOWARG0.CMD"] ----------- [C:] [\bin] [SHOWARG0] [.CMD] ["showarg0".cmd] ----------- [C:] [\bin] [showarg0] [.cmd] ["sho"warg0.cmd] ----------- [C:] [\bin] [showarg0] [.cmd] ["sho"warg0] --------------- [C:] [\bin] [showarg0] [.CMD] ["C":\bin\showarg0.cmd] ---- [C:] [\bin] [showarg0] [.cmd] ["C:"\bin\showarg0.cmd] ---- [C:] [\bin] [showarg0] [.cmd] ["C:"bin\showarg0.cmd] ---- [C:] [\bin] [showarg0] [.cmd] ["c:"bin\showarg0.CMD] ---- [c:] [\bin] [showarg0] [.CMD] ["C:\bin\showarg0"] -------- [C:] [\bin] [showarg0] [.CMD]
I see two differences:
- In most cases, when a path starts with a quote, Windows somehow doesn't parse the path correctly and/or doesn't find the batch file in the PATH.
- As long as Windows *does* find the batch file, it uses the canonical case for the path, filename, and extension. It doesn't canonicalize the drive; instead it uses the drive from the PATH or %0. I also tested a SMB share on XP and Win10 (\nAs\nAs and \NaS\NaS), and Windows didn't canonicalize the server name or share name. (Maybe it never does.)
https://bugs.winehq.org/show_bug.cgi?id=44373
Ryan Prichard ryan.prichard@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Summary|cmd's %0 path variables |cmd's path variables (e.g. |(e.g. %~dp0) don't match |%~dp0 / %~dp1) don't match |those of Windows (w.r.t. |those of Windows (w.r.t. |case and quoting) |case and quoting)
https://bugs.winehq.org/show_bug.cgi?id=44373
--- Comment #1 from Ryan Prichard ryan.prichard@gmail.com --- The case canonicalization differences can also affect %1:
c:\Bin\ShowArg1.Cmd
@echo [%1] -------------------- [%~d1] [%~p1] [%~n1] [%~x1]
Win10.0.16299.125:
C:\Windows>c:\Bin\ShowArg1 SysTem32\NotePad.Exe [SysTem32\NotePad.Exe] -------------------- [C:] [\Windows\System32] [notepad] [.exe]
C:\Windows>c:\Bin\ShowArg1 "SysTem32\NotePad.Exe" ["SysTem32\NotePad.Exe"] -------------------- [C:] [\Windows\System32] [notepad] [.exe]
C:\Windows>c:\Bin\ShowArg1 "SysTem32\NotePad".Exe ["SysTem32\NotePad".Exe] -------------------- [C:] [\Windows\System32] [NotePad"] [.Exe]
C:\Windows>c:\Bin\ShowArg1 Sys"Tem32\NotePad".Exe [Sys"Tem32\NotePad".Exe] -------------------- [C:] [\Windows\Sys"Tem32] [NotePad"] [.Exe]
C:\Windows>c:\Bin\ShowArg1 Sys"Tem"32\NotePad.Exe [Sys"Tem"32\NotePad.Exe] -------------------- [C:] [\Windows\Sys"Tem"32] [NotePad] [.Exe]
Wine 3.0-rc6:
C:\windows>c:\Bin\ShowArg1 SysTem32\NotePad.Exe [SysTem32\NotePad.Exe] -------------------- [C:] [\windows\SysTem32] [NotePad] [.Exe]
C:\windows>c:\Bin\ShowArg1 "SysTem32\NotePad.Exe" ["SysTem32\NotePad.Exe"] -------------------- [C:] [\windows\SysTem32] [NotePad] [.Exe]
C:\windows>c:\Bin\ShowArg1 "SysTem32\NotePad".Exe ["SysTem32\NotePad".Exe] -------------------- [C:] [\windows\SysTem32] [NotePad] [.Exe]
C:\windows>c:\Bin\ShowArg1 Sys"Tem32\NotePad".Exe [Sys"Tem32\NotePad".Exe] -------------------- [C:] [\windows\SysTem32] [NotePad] [.Exe]
C:\windows>c:\Bin\ShowArg1 Sys"Tem"32\NotePad.Exe [Sys"Tem"32\NotePad.Exe] -------------------- [C:] [\windows\SysTem32] [NotePad] [.Exe]
https://bugs.winehq.org/show_bug.cgi?id=44373
Jason Edmeades us@edmeades.me.uk changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever confirmed|0 |1 CC| |us@edmeades.me.uk
--- Comment #2 from Jason Edmeades us@edmeades.me.uk --- I started to look into the canonical case part of this but am really questioning the benefit unless we know an app is affected by it.
I'm attaching a patch which starts to fix it for the case of the filename portion but FindFirstFile is the best way to get the case of a filename, but it fails on wine when passed an explicit file and just returns what is passed in. I'll submit a bug with test case for this
To do this properly, we need to get the case of all the path leading up to the filename as well, which isnt worth the performance issue unless its causing problems, which makes me question the benefit if no apps need this
As to the other part, from your results it looks like on Windows if you start with quotes, then the leading quote and if there is one, trailing quote is removed. It then behaves as normal (searches path etc) except the 'full path' used to represent the batch program is 'replaced' by the parameter without the quotes. This is odd, and whilst we could implement it by keeping a second copy of data (where the file is, and where we say it is), I again question the benefit of adding the complexity without a need.
My gut feeling is this should be closed as wontfix, unless an app comes along which needs specifric behaviour. Fabian was right, its worth having bugs to highlight where there is differences, and if it was easy I would have fixed this. I wont close as its not really my call, but wanted to add my thoughts in here as I work some of the cmd bugs.
https://bugs.winehq.org/show_bug.cgi?id=44373
--- Comment #3 from Jason Edmeades us@edmeades.me.uk --- Created attachment 62001 --> https://bugs.winehq.org/attachment.cgi?id=62001 Try to fix the canonical case of the file