diff --git a/Source/Common/NMR_StringUtils.cpp b/Source/Common/NMR_StringUtils.cpp index 7c663e492..81dad377b 100644 --- a/Source/Common/NMR_StringUtils.cpp +++ b/Source/Common/NMR_StringUtils.cpp @@ -153,6 +153,9 @@ namespace NMR { __NMRASSERT(pwszValue); nfDouble dResult = 0.0; + //skip leading whitespaces + for (; *pszValue && *pszValue == ' '; pszValue++); + // Convert to double and make a input and range check! auto answer = fast_float::from_chars(pszValue, pszValue + strlen(pszValue), dResult); diff --git a/Tests/CPP_Bindings/Source/Reader.cpp b/Tests/CPP_Bindings/Source/Reader.cpp index 03e4b4698..27f911e31 100644 --- a/Tests/CPP_Bindings/Source/Reader.cpp +++ b/Tests/CPP_Bindings/Source/Reader.cpp @@ -161,9 +161,17 @@ namespace Lib3MF TEST_F(Reader, ReadVerticesWithLeadingPLUSSign) { // This file P_XXM_0519_01.3mf contains vertices with leading + sign e.g +1E+2. - // The 3MFReader allows leading = sign at NMR_StringUtils::fnStringToDouble when reading this file. + // The 3MFReader allows leading + sign at NMR_StringUtils::fnStringToDouble when reading this file. auto reader = model->QueryReader("3mf"); reader->ReadFromFile(sTestFilesPath + "/Reader/" + "P_XXM_0519_01.3mf"); CheckReaderWarnings(Reader::reader3MF, 0); } + + TEST_F(Reader, ReadVerticesValueWithLeadingTrialingSpaces) { + // This file cam-51476-test.3mf contains vertices with leading whitespaces. + // The 3MFReader allows leading/trialing whitespaces at NMR_StringUtils::fnStringToDouble when reading this file. + auto reader = model->QueryReader("3mf"); + reader->ReadFromFile(sTestFilesPath + "/Reader/" + "cam_51476_test.3mf"); + CheckReaderWarnings(Reader::reader3MF, 0); + } } diff --git a/Tests/TestFiles/Reader/cam_51476_test.3mf b/Tests/TestFiles/Reader/cam_51476_test.3mf new file mode 100644 index 000000000..97d858084 Binary files /dev/null and b/Tests/TestFiles/Reader/cam_51476_test.3mf differ