https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8ce4b73920f76de6a48bd…
commit 8ce4b73920f76de6a48bd04d3b0fe6e21207da7b
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Thu Jul 13 16:07:37 2023 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Fri Jul 14 14:36:55 2023 +0200
[CMD] Correctly honour the "short" path flag in %~var enhanced variables expansion. (#5433)
CORE-14096, CORE-8002
Patch based on an earlier fix attempt by Doug Lyons.
It should fix the problem observed by contributor 'whindsaks' in PR #5403.
This bug has always been present since the implementation of this feature
in commit a1eb1f6ba (r40024).
The expansion of %~dpX ennhanced variables used to incorrectly show some
directories in uppercase. For example:
```batch
:: testcmd.cmd
echo '%~dp0'
echo '%~dps0'
echo '%~s0'
```
would show:
```
P:\Documents and Settings\Administrator\Desktop>echo 'P:\Documents and Settings\Administrator\DESKTOP\'
'P:\Documents and Settings\Administrator\DESKTOP\'
P:\Documents and Settings\Administrator\Desktop>echo 'P:\DOCUME~1\ADMINI~1\DESKTOP\'
'P:\DOCUME~1\ADMINI~1\DESKTOP\'
P:\Documents and Settings\Administrator\Desktop>echo 'P:\DOCUME~1\ADMINI~1\DESKTOP\testcmd.cmd'
'P:\DOCUME~1\ADMINI~1\DESKTOP\testcmd.cmd'
```
instead of the correct:
```
P:\Documents and Settings\Administrator\Desktop>echo 'P:\Documents and Settings\Administrator\Desktop\'
'P:\Documents and Settings\Administrator\Desktop\'
P:\Documents and Settings\Administrator\Desktop>echo 'P:\DOCUME~1\ADMINI~1\DESKTOP\'
'P:\DOCUME~1\ADMINI~1\DESKTOP\'
P:\Documents and Settings\Administrator\Desktop>echo 'P:\DOCUME~1\ADMINI~1\DESKTOP\testcmd.cmd'
'P:\DOCUME~1\ADMINI~1\DESKTOP\testcmd.cmd'
```
The reason was a wrong handling of the presence (or absence) of the
"short" path format specifier 's' in those enhanced variables.
In the examples above, the "Desktop" sub-directory has a short-path
name available (because it is in a FAT partition). The short-path name
was used some times also even with the 's' specifier absent.
Co-authored-by: Doug Lyons <douglyons(a)douglyons.com>
---
base/shell/cmd/cmd.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/base/shell/cmd/cmd.c b/base/shell/cmd/cmd.c
index 0f16229172f..126f2f4cb31 100644
--- a/base/shell/cmd/cmd.c
+++ b/base/shell/cmd/cmd.c
@@ -1158,11 +1158,9 @@ GetEnhancedVar(
if (hFind != INVALID_HANDLE_VALUE)
{
PTSTR FixedComponent = w32fd.cFileName;
- if (*w32fd.cAlternateFileName &&
- ((Modifiers & M_SHORT) || !_tcsicmp(In, w32fd.cAlternateFileName)))
- {
+ if ((Modifiers & M_SHORT) && *w32fd.cAlternateFileName)
FixedComponent = w32fd.cAlternateFileName;
- }
+
FindClose(hFind);
if (Out + _tcslen(FixedComponent) + 1 >= &FixedPath[ARRAYSIZE(FixedPath)])