oleaut32: Do not skip the first decimal digit in VarParseNumFromStr().

Add more tests to probe what happens if the integral part is omitted.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52476
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
David Kahurani 2022-03-07 18:47:31 +01:00 committed by Alexandre Julliard
parent 3c2e6efb5a
commit a4ba88c0ff
2 changed files with 48 additions and 1 deletions

View file

@ -1775,6 +1775,45 @@ static void test_VarParseNumFromStrEn(void)
EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,0);
EXPECT2(1,FAILDIG);
/* Skipping the integer part is not an error */
CONVERT(".2", NUMPRS_DECIMAL);
EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,-1);
EXPECT2(2,FAILDIG);
/* Even zero gets an exponent (it sort of indicates 'precision') */
CONVERT(".0", NUMPRS_DECIMAL);
EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,-1);
EXPECT2(0,FAILDIG);
CONVERT(".000", NUMPRS_DECIMAL);
EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,4,0,-3);
EXPECTRGB(0,0);
EXPECTRGB(3,FAILDIG);
CONVERT("$.02", NUMPRS_CURRENCY|NUMPRS_DECIMAL);
EXPECT(1,NUMPRS_CURRENCY|NUMPRS_DECIMAL,NUMPRS_CURRENCY|NUMPRS_DECIMAL,4,0,-2);
EXPECT2(2,FAILDIG);
CONVERT(".001", NUMPRS_DECIMAL);
EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,4,0,-3);
EXPECT2(1,FAILDIG);
CONVERT(".101", NUMPRS_DECIMAL);
EXPECT(3,NUMPRS_DECIMAL,NUMPRS_DECIMAL,4,0,-3);
EXPECT2(1,0);
EXPECTRGB(2,1);
EXPECTRGB(3,FAILDIG);
CONVERT(".30", NUMPRS_DECIMAL);
EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
/* See the NUMPRS_THOUSANDS comment about trailing zeroes */
EXPECTRGB(0,3);
EXPECTRGB(2,FAILDIG);
/* But skipping both the integer and decimal part is not allowed */
CONVERT(".", NUMPRS_DECIMAL);
EXPECTFAIL;
/* Consumes only one decimal point */
CONVERT("1.1.", NUMPRS_DECIMAL);
EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
@ -2131,6 +2170,14 @@ static void test_VarParseNumFromStrFr(void)
CONVERT("1.2", NUMPRS_DECIMAL);
EXPECT(1,NUMPRS_DECIMAL,0,1,0,0);
EXPECT2(1,FAILDIG);
/* The integer part can still be omitted */
CONVERT(",2", NUMPRS_DECIMAL);
EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,-1);
EXPECT2(2,FAILDIG);
CONVERT(".2", NUMPRS_DECIMAL);
EXPECTFAIL;
}
static void test_VarParseNumFromStrMisc(void)

View file

@ -1633,7 +1633,7 @@ HRESULT WINAPI VarParseNumFromStr(const OLECHAR *lpszStr, LCID lcid, ULONG dwFla
/* If we have no digits so far, skip leading zeros */
if (!pNumprs->cDig)
{
while (lpszStr[1] == '0')
while (*lpszStr == '0')
{
dwState |= B_LEADING_ZERO;
cchUsed++;