diff --git a/src/OpenColorIO/ParseUtils.cpp b/src/OpenColorIO/ParseUtils.cpp index df3961867..94eb3854a 100644 --- a/src/OpenColorIO/ParseUtils.cpp +++ b/src/OpenColorIO/ParseUtils.cpp @@ -786,28 +786,38 @@ std::string JoinStringEnvStyle(const StringUtils::StringVec & outputvec) { std::string result; const int nElement = static_cast(outputvec.size()); - for( int i = 0; i < nElement; ++i ) + if( nElement == 0 ) + { + return ""; + } + + // We check if the value contains a symbol that could be interpreted as a separator + // and if it is not already surrounded by quotes + const std::string& firstValue = outputvec[0]; + if( firstValue.find_first_of(",:") != std::string::npos && + firstValue.size() > 1 && + firstValue[0] != '"' && + firstValue[firstValue.size() - 1] != '"' ) + { + result += "\"" + firstValue + "\""; + } + else + { + result += firstValue; + } + + for( int i = 1; i < nElement; ++i ) { - // We check if the value contains a symbol that could be interpreted as a separator - // and if it is not already surrounded by quotes if( outputvec[i].find_first_of(",:") != std::string::npos && outputvec[i].size() > 1 && outputvec[i][0] != '"' && outputvec[i][outputvec[i].size() - 1] != '"' ) { - result += "\"" + outputvec[i] + "\""; - if( outputvec[i] != outputvec.back() ) - { - result += ", "; - } - } - else if( i == nElement - 1 ) - { - result += outputvec[i]; + result += ", \"" + outputvec[i] + "\""; } else { - result += outputvec[i] + ", "; + result += ", " + outputvec[i]; } } diff --git a/tests/cpu/ParseUtils_tests.cpp b/tests/cpu/ParseUtils_tests.cpp index 55823c5d2..2af2ce84b 100644 --- a/tests/cpu/ParseUtils_tests.cpp +++ b/tests/cpu/ParseUtils_tests.cpp @@ -485,7 +485,6 @@ OCIO_ADD_TEST(ParseUtils, join_string_env_style) OCIO_CHECK_EQUAL( "This, is, a, test", OCIO::JoinStringEnvStyle(outputvec) ); outputvec.clear(); - outputvec = { "This:is", "a:test" }; OCIO_CHECK_EQUAL( "\"This:is\", \"a:test\"", OCIO::JoinStringEnvStyle(outputvec) ); outputvec.clear();