Commit 8d9eb707 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

kernel32/profile: Trim spaces from section names on load.

parent 1c84acd0
......@@ -292,6 +292,16 @@ static inline ENCODING PROFILE_DetectTextEncoding(const void * buffer, int * len
return ENCODING_ANSI;
}
static void profile_trim_spaces(WCHAR **start, WCHAR **end)
{
WCHAR *s = *start, *e = *end;
while (s < e && PROFILE_isspaceW(*s)) s++;
while ((e > s) && PROFILE_isspaceW(e[-1])) e--;
*start = s;
*end = e;
}
/***********************************************************************
* PROFILE_Load
......@@ -302,8 +312,8 @@ static PROFILESECTION *PROFILE_Load(HANDLE hFile, ENCODING * pEncoding)
{
void *buffer_base, *pBuffer;
WCHAR * szFile;
const WCHAR *szLineStart, *szLineEnd;
const WCHAR *szValueStart, *szEnd, *next_line;
WCHAR *szLineStart, *szLineEnd, *next_line;
const WCHAR *szValueStart, *szEnd;
int len;
PROFILESECTION *section, *first_section;
PROFILESECTION **next_section;
......@@ -400,8 +410,7 @@ static PROFILESECTION *PROFILE_Load(HANDLE hFile, ENCODING * pEncoding)
szLineEnd = next_line;
/* get rid of white space */
while (szLineStart < szLineEnd && PROFILE_isspaceW(*szLineStart)) szLineStart++;
while ((szLineEnd > szLineStart) && PROFILE_isspaceW(szLineEnd[-1])) szLineEnd--;
profile_trim_spaces(&szLineStart, &szLineEnd);
if (szLineStart >= szLineEnd) continue;
......@@ -415,8 +424,13 @@ static PROFILESECTION *PROFILE_Load(HANDLE hFile, ENCODING * pEncoding)
}
else
{
/* Skip brackets */
szLineStart++;
len -= 2;
szLineEnd = szLineStart + len;
profile_trim_spaces(&szLineStart, &szLineEnd);
len = szLineEnd - szLineStart;
/* no need to allocate +1 for NULL terminating character as
* already included in structure */
if (!(section = HeapAlloc( GetProcessHeap(), 0, sizeof(*section) + len * sizeof(WCHAR) )))
......
......@@ -80,6 +80,7 @@ static void test_profile_int(void)
{ SECTION, KEY, "B4294967297", TESTFILE, 1, 0},
};
int i, num_test = ARRAY_SIZE(profileInt);
char section[64];
UINT res;
DeleteFileA( TESTFILE);
......@@ -93,6 +94,12 @@ static void test_profile_int(void)
profileInt[i].defaultVal, profileInt[i].iniFile);
ok((res == profileInt[i].result), "test<%02d>: ret<%010u> exp<%010u>\n",
i, res, profileInt[i].result);
sprintf(section, " %s ", profileInt[i].section);
res = GetPrivateProfileIntA(profileInt[i].section, profileInt[i].key,
profileInt[i].defaultVal, profileInt[i].iniFile);
ok((res == profileInt[i].result), "test<%02d>: ret<%010u> exp<%010u>\n",
i, res, profileInt[i].result);
}
DeleteFileA( TESTFILE);
......@@ -270,7 +277,7 @@ static void test_profile_sections_names(void)
DWORD count;
char buf[100];
WCHAR bufW[100];
static const char content[]="[section1]\r\n[section2]\r\n[section3]\r\n";
static const char content[]="[ section1 ]\r\n[section2]\r\n[section3]\r\n";
static const char testfile3[]=".\\testwine3.ini";
static const WCHAR testfile3W[]={ '.','\\','t','e','s','t','w','i','n','e','3','.','i','n','i',0 };
static const WCHAR not_here[] = {'.','\\','n','o','t','_','h','e','r','e','.','i','n','i',0};
......@@ -288,6 +295,7 @@ static void test_profile_sections_names(void)
ok( ret == 27, "expected return size 27, got %d\n", ret );
ok( (buf[ret-1] == 0 && buf[ret] == 0),
"returned buffer not terminated with double-null\n" );
ok( !strcmp(buf, "section1"), "Unexpected content %s.\n", debugstr_a(buf));
/* Test with exactly fitting buffer */
memset(buf, 0xc, sizeof(buf));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment