Skip to content

Commit 848ad61

Browse files
madewokherdHBelusca
andcommitted
[SHLWAPI][WINESYNC] Import PathRemoveBlanks wine fix + adaptation for ReactOS (reactos#7636)
kernelbase: Always remove trailing spaces in PathRemoveBlanks. Signed-off-by: Esme Povirk <[email protected]> Signed-off-by: Alexandre Julliard <[email protected]> wine commit id 404cd8a92bd99332a7ef8ec96edbf5aeea8cab76 by Esme Povirk <[email protected]> Co-authored-by: Hermès Bélusca-Maïto <[email protected]>
1 parent f189d8c commit 848ad61

File tree

2 files changed

+77
-26
lines changed
  • dll/win32/shlwapi
  • modules/rostests/winetests/shlwapi

2 files changed

+77
-26
lines changed

dll/win32/shlwapi/path.c

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -891,51 +891,57 @@ LPWSTR WINAPI PathRemoveBackslashW( LPWSTR lpszPath )
891891
* RETURNS
892892
* Nothing.
893893
*/
894-
VOID WINAPI PathRemoveBlanksA(LPSTR lpszPath)
894+
void WINAPI PathRemoveBlanksA(LPSTR pszPath)
895895
{
896-
TRACE("(%s)\n", debugstr_a(lpszPath));
896+
LPSTR start, first;
897897

898-
if(lpszPath && *lpszPath)
899-
{
900-
LPSTR start = lpszPath;
898+
TRACE("(%s)\n", debugstr_a(pszPath));
901899

902-
while (*lpszPath == ' ')
903-
lpszPath = CharNextA(lpszPath);
900+
if (!pszPath || !*pszPath)
901+
return;
902+
903+
start = first = pszPath;
904904

905-
while(*lpszPath)
906-
*start++ = *lpszPath++;
905+
while (*pszPath == ' ')
906+
pszPath = CharNextA(pszPath);
907+
908+
while (*pszPath)
909+
*start++ = *pszPath++;
910+
911+
if (start != first)
912+
while (start[-1] == ' ')
913+
start--;
907914

908-
if (start != lpszPath)
909-
while (start[-1] == ' ')
910-
start--;
911915
*start = '\0';
912-
}
913916
}
914917

915918
/*************************************************************************
916919
* PathRemoveBlanksW [SHLWAPI.@]
917920
*
918921
* See PathRemoveBlanksA.
919922
*/
920-
VOID WINAPI PathRemoveBlanksW(LPWSTR lpszPath)
923+
void WINAPI PathRemoveBlanksW(LPWSTR pszPath)
921924
{
922-
TRACE("(%s)\n", debugstr_w(lpszPath));
925+
LPWSTR start, first;
923926

924-
if(lpszPath && *lpszPath)
925-
{
926-
LPWSTR start = lpszPath;
927+
TRACE("(%s)\n", debugstr_w(pszPath));
927928

928-
while (*lpszPath == ' ')
929-
lpszPath++;
929+
if (!pszPath || !*pszPath)
930+
return;
931+
932+
start = first = pszPath;
930933

931-
while(*lpszPath)
932-
*start++ = *lpszPath++;
934+
while (*pszPath == ' ')
935+
pszPath++;
936+
937+
while (*pszPath)
938+
*start++ = *pszPath++;
939+
940+
if (start != first)
941+
while (start[-1] == ' ')
942+
start--;
933943

934-
if (start != lpszPath)
935-
while (start[-1] == ' ')
936-
start--;
937944
*start = '\0';
938-
}
939945
}
940946

941947
/*************************************************************************

modules/rostests/winetests/shlwapi/path.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,50 @@ static void test_PathUndecorate(void)
17121712
PathUndecorateW(NULL);
17131713
}
17141714

1715+
static void test_PathRemoveBlanks(void)
1716+
{
1717+
struct remove_blanks_test {
1718+
const char* input;
1719+
const char* expected;
1720+
};
1721+
struct remove_blanks_test tests[] = {
1722+
{"", ""},
1723+
{" ", ""},
1724+
{"test", "test"},
1725+
{" test", "test"},
1726+
{" test", "test"},
1727+
{"test ", "test"},
1728+
{"test ", "test"},
1729+
{" test ", "test"},
1730+
{" test ", "test"}};
1731+
char pathA[MAX_PATH];
1732+
WCHAR pathW[MAX_PATH];
1733+
int i, ret;
1734+
const UINT CP_ASCII = 20127;
1735+
1736+
PathRemoveBlanksW(NULL);
1737+
PathRemoveBlanksA(NULL);
1738+
1739+
for (i=0; i < ARRAY_SIZE(tests); i++)
1740+
{
1741+
strcpy(pathA, tests[i].input);
1742+
PathRemoveBlanksA(pathA);
1743+
ok(strcmp(pathA, tests[i].expected) == 0, "input string '%s', expected '%s', got '%s'\n",
1744+
tests[i].input, tests[i].expected, pathA);
1745+
1746+
ret = MultiByteToWideChar(CP_ASCII, MB_ERR_INVALID_CHARS, tests[i].input, -1, pathW, MAX_PATH);
1747+
ok(ret != 0, "MultiByteToWideChar failed for '%s'\n", tests[i].input);
1748+
1749+
PathRemoveBlanksW(pathW);
1750+
1751+
ret = WideCharToMultiByte(CP_ASCII, 0, pathW, -1, pathA, MAX_PATH, NULL, NULL);
1752+
ok(ret != 0, "WideCharToMultiByte failed for %s from test string '%s'\n", wine_dbgstr_w(pathW), tests[i].input);
1753+
1754+
ok(strcmp(pathA, tests[i].expected) == 0, "input string '%s', expected '%s', got '%s'\n",
1755+
tests[i].input, tests[i].expected, pathA);
1756+
}
1757+
}
1758+
17151759
START_TEST(path)
17161760
{
17171761
HMODULE hShlwapi = GetModuleHandleA("shlwapi.dll");
@@ -1759,4 +1803,5 @@ START_TEST(path)
17591803
test_PathIsRelativeW();
17601804
test_PathStripPathA();
17611805
test_PathUndecorate();
1806+
test_PathRemoveBlanks();
17621807
}

0 commit comments

Comments
 (0)