diff --git a/src/base/stringUtils.cpp b/src/base/stringUtils.cpp index 44f8b19bb..6aea5ce76 100644 --- a/src/base/stringUtils.cpp +++ b/src/base/stringUtils.cpp @@ -147,12 +147,13 @@ compositionMap parseCompString(const std::string& ss, // this case, take the current substring as part of the key and look // to the right of the next colon for the corresponding value. // Otherwise, this is an invalid composition string. - std::string testname = ss.substr(valstart, stop-colon-1); + std::string testname = ss.substr(start, stop-colon-1); if (testname.find_first_of(" \n\t") != npos) { // Space, tab, and newline are never allowed in names throw; } else if (ss.substr(valstart, stop-colon-1).find(':') != npos) { left = colon + 1; + stop = 0; // Force another iteration of this loop continue; } else { throw; diff --git a/test/general/string_processing.cpp b/test/general/string_processing.cpp index 0c347df3d..ba9aee59d 100644 --- a/test/general/string_processing.cpp +++ b/test/general/string_processing.cpp @@ -33,6 +33,13 @@ TEST(parseCompString, name_with_colon) ASSERT_DOUBLE_EQ(1e-4, c["baz"]); } +TEST(parseCompString, name_with_final_colon) +{ + compositionMap c = parseCompString("co:lons::1.0"); + ASSERT_EQ((size_t) 1, c.size()); + ASSERT_DOUBLE_EQ(1.0, c["co:lons:"]); +} + TEST(parseCompString, default_values) { std::vector x = { "foo", "bar", "baz" };