diff --git a/CMakeLists.txt b/CMakeLists.txt index 10a011314..fe8004a5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,6 +123,9 @@ file(GLOB list(FILTER LIBS_INCLUDE EXCLUDE REGEX "zlib|libzip|libressl") target_include_directories(${PROJECT_NAME} PRIVATE ${LIBS_INCLUDE}) +# allow FASTFLOAT_ALLOWS_LEADING_PLUS +add_definitions(-DFASTFLOAT_ALLOWS_LEADING_PLUS=1) + target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR_AUTOGENERATED}/Source) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Include/API) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Include) diff --git a/Source/Common/NMR_StringUtils.cpp b/Source/Common/NMR_StringUtils.cpp index 63166d6e8..7c663e492 100644 --- a/Source/Common/NMR_StringUtils.cpp +++ b/Source/Common/NMR_StringUtils.cpp @@ -161,7 +161,13 @@ namespace NMR { { throw CNMRException(NMR_ERROR_EMPTYSTRINGTODOUBLECONVERSION); } - + else if (answer.ptr) // Invalidate comma as decimal separator + { + if (answer.ptr[0] == ',') + { + throw CNMRException(NMR_ERROR_INVALIDSTRINGTODOUBLECONVERSION); + } + } if ((dResult == HUGE_VAL) || (dResult == -HUGE_VAL)) throw CNMRException(NMR_ERROR_STRINGTODOUBLECONVERSIONOUTOFRANGE); diff --git a/Tests/CPP_Bindings/Source/Reader.cpp b/Tests/CPP_Bindings/Source/Reader.cpp index fa2c81b89..03e4b4698 100644 --- a/Tests/CPP_Bindings/Source/Reader.cpp +++ b/Tests/CPP_Bindings/Source/Reader.cpp @@ -149,4 +149,21 @@ namespace Lib3MF auto reader = model->QueryReader("3mf"); ASSERT_SPECIFIC_THROW(reader->ReadFromFile(sTestFilesPath + "/Reader/" + "GEN-M-ADA-ITEM-TRANSFORM-0.3mf"), ELib3MFException); } + + + TEST_F(Reader, ReadVerticesCommaSeparatedValue) { + // This file N_XXX_0422_01.3mf contains vertices with comma-separated values. + // The 3MFReader should throw an error at NMR_StringUtils::fnStringToDouble when reading this file because + // comma-separated values are not allowed in 3MF files. + auto reader = model->QueryReader("3mf"); + ASSERT_SPECIFIC_THROW(reader->ReadFromFile(sTestFilesPath + "/Reader/" + "N_XXX_0422_01.3mf"), ELib3MFException); + } + + 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. + auto reader = model->QueryReader("3mf"); + reader->ReadFromFile(sTestFilesPath + "/Reader/" + "P_XXM_0519_01.3mf"); + CheckReaderWarnings(Reader::reader3MF, 0); + } } diff --git a/Tests/TestFiles/Reader/N_XXX_0422_01.3mf b/Tests/TestFiles/Reader/N_XXX_0422_01.3mf new file mode 100644 index 000000000..b10793a27 Binary files /dev/null and b/Tests/TestFiles/Reader/N_XXX_0422_01.3mf differ diff --git a/Tests/TestFiles/Reader/P_XXM_0519_01.3mf b/Tests/TestFiles/Reader/P_XXM_0519_01.3mf new file mode 100644 index 000000000..cf19de339 Binary files /dev/null and b/Tests/TestFiles/Reader/P_XXM_0519_01.3mf differ