Skip to content

Commit f3fb3c7

Browse files
committed
Fix conversion of empty and whitespace string to double
1 parent 2c01b5d commit f3fb3c7

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

src/scratch/value_functions_p.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,8 @@ extern "C"
232232
if (ok)
233233
*ok = false;
234234

235-
if (!s || *s == '\0') {
236-
if (ok)
237-
*ok = true;
238-
235+
if (!s || *s == '\0')
239236
return 0;
240-
}
241237

242238
const size_t len = strlen(s);
243239
const char *begin = s;
@@ -251,11 +247,8 @@ extern "C"
251247
while (end > begin && IS_SPACE(*(end - 1)))
252248
--end;
253249

254-
if (begin == end) { // All spaces case
255-
if (ok)
256-
*ok = true;
257-
return 0.0;
258-
}
250+
if (begin == end) // All spaces case
251+
return 0;
259252

260253
// Try to convert integer early
261254
bool isInt = false;

test/scratch_classes/value_test.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ TEST(ValueTest, StdStringConstructor)
285285
ASSERT_FALSE(v.isNaN());
286286
ASSERT_FALSE(v.isNumber());
287287
ASSERT_TRUE(v.isValidNumber());
288-
ASSERT_TRUE(v.isInt());
288+
ASSERT_FALSE(v.isInt());
289289
ASSERT_FALSE(v.isBool());
290290
ASSERT_TRUE(v.isString());
291291
}
@@ -299,8 +299,8 @@ TEST(ValueTest, StdStringConstructor)
299299
ASSERT_FALSE(v.isNegativeInfinity());
300300
ASSERT_FALSE(v.isNaN());
301301
ASSERT_FALSE(v.isNumber());
302-
ASSERT_TRUE(v.isValidNumber());
303-
ASSERT_TRUE(v.isInt());
302+
ASSERT_FALSE(v.isValidNumber());
303+
ASSERT_FALSE(v.isInt());
304304
ASSERT_FALSE(v.isBool());
305305
ASSERT_TRUE(v.isString());
306306
}
@@ -2536,6 +2536,31 @@ TEST(ValueTest, EqualityOperators)
25362536
ASSERT_TRUE(v3 != v4);
25372537
}
25382538

2539+
{
2540+
Value v1 = " ";
2541+
Value v2 = "";
2542+
Value v3 = "0";
2543+
Value v4 = 0;
2544+
2545+
ASSERT_FALSE(v1 == v2);
2546+
ASSERT_TRUE(v1 != v2);
2547+
2548+
ASSERT_FALSE(v1 == v3);
2549+
ASSERT_TRUE(v1 != v3);
2550+
2551+
ASSERT_FALSE(v1 == v4);
2552+
ASSERT_TRUE(v1 != v4);
2553+
2554+
ASSERT_FALSE(v2 == v3);
2555+
ASSERT_TRUE(v2 != v3);
2556+
2557+
ASSERT_FALSE(v2 == v4);
2558+
ASSERT_TRUE(v2 != v4);
2559+
2560+
ASSERT_TRUE(v3 == v4);
2561+
ASSERT_FALSE(v3 != v4);
2562+
}
2563+
25392564
{
25402565
Value v1(SpecialValue::Infinity);
25412566
Value v2(SpecialValue::Infinity);

0 commit comments

Comments
 (0)