persistence: fixing crash with space-only values
This commit is contained in:
parent
22682f933a
commit
00112bbe10
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user