提交 00112bbe 编写于 作者: P Philipp Hasper

persistence: fixing crash with space-only values

上级 22682f93
......@@ -1852,7 +1852,7 @@ icvYMLWriteString( CvFileStorage* fs, const char* key,
if( quote || len == 0 || str[0] != str[len-1] || (str[0] != '\"' && str[0] != '\'') )
{
int need_quote = quote || len == 0;
int need_quote = quote || len == 0 || str[0] == ' ';
data = buf;
*data++ = '\"';
for( i = 0; i < len; i++ )
......
......@@ -578,6 +578,22 @@ TEST(Core_InputOutput, FileStorageKey)
ASSERT_STREQ(f.releaseAndGetString().c_str(), expected.c_str());
}
TEST(Core_InputOutput, FileStorageSpaces)
{
cv::FileStorage f("dummy.yml", cv::FileStorage::WRITE | cv::FileStorage::MEMORY);
const int valueCount = 5;
std::string values[5] = { "", " ", " ", " a", " some string" };
for (size_t i = 0; i < valueCount; i++) {
EXPECT_NO_THROW(f << cv::format("key%d", i) << values[i]);
}
cv::FileStorage f2(f.releaseAndGetString(), cv::FileStorage::READ | cv::FileStorage::MEMORY);
std::string valuesRead[valueCount];
for (size_t i = 0; i < valueCount; i++) {
EXPECT_NO_THROW(f2[cv::format("key%d", i)] >> valuesRead[i]);
ASSERT_STREQ(values[i].c_str(), valuesRead[i].c_str());
}
}
TEST(Core_InputOutput, filestorage_yml_compatibility)
{
// TODO:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册