diff --git a/base/base_tests/string_utils_test.cpp b/base/base_tests/string_utils_test.cpp index bd54fcaef3..9342daf3e0 100644 --- a/base/base_tests/string_utils_test.cpp +++ b/base/base_tests/string_utils_test.cpp @@ -137,6 +137,9 @@ UNIT_TEST(to_double) string s; double d; + s = ""; + TEST(!strings::to_double(s, d), ()); + s = "0.123"; TEST(strings::to_double(s, d), ()); TEST_ALMOST_EQUAL_ULPS(0.123, d, ()); @@ -159,6 +162,9 @@ UNIT_TEST(to_double) s = "labuda"; TEST(!strings::to_double(s, d), ()); + + s = "123.456 we don't parse it."; + TEST(!strings::to_double(s, d), ()); } UNIT_TEST(to_int) diff --git a/base/string_utils.cpp b/base/string_utils.cpp index 971817ba99..a9b59425e4 100644 --- a/base/string_utils.cpp +++ b/base/string_utils.cpp @@ -81,7 +81,7 @@ bool to_double(char const * s, double & d) { char * stop; d = strtod(s, &stop); - return stop && *stop == 0; + return stop && *stop == 0 && s != stop; } UniString MakeLowerCase(UniString const & s)