Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/sbml/SBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6470,6 +6470,32 @@ SBase::reconstructRDFAnnotation()
}
}

if (mAnnotation != NULL)
{
int rdfIndex = mAnnotation->getIndex("RDF");
if (rdfIndex >= 0)
{
XMLNode& rdfNode = mAnnotation->getChild((unsigned int)rdfIndex);

// Iterate backwards since we are removing items from the list
for (int i = (int)rdfNode.getNumChildren() - 1; i >= 0; i--)
{
XMLNode& child = rdfNode.getChild((unsigned int)i);

// If the Description node has no inner children, delete it
if (child.getName() == "Description" && child.getNumChildren() == 0)
{
delete rdfNode.removeChild((unsigned int)i);
}
}

// If the RDF node itself is now completely empty, delete it as well
if (rdfNode.getNumChildren() == 0)
{
delete mAnnotation->removeChild((unsigned int)rdfIndex);
}
}
}

if (history != NULL) delete history;
if (cvTerms != NULL) delete cvTerms;
Expand Down
30 changes: 30 additions & 0 deletions src/sbml/test/TestSBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2654,6 +2654,35 @@ START_TEST(test_SBase_userData1)
}
END_TEST

START_TEST (test_SBase_unsetModifiedDates_issue354)
{
Model* m = new Model(3, 2);
m->setMetaId("foo");

ModelHistory* h = new ModelHistory();
Date* d = new Date("2019-07-29T10:53:09Z");
h->addModifiedDate(d);

m->setModelHistory(h);

// Ensure the date was successfully added
fail_unless(m->getNumModifiedDates() == 1);

// Unset the dates (This triggers the new cleanup logic we wrote in SBase.cpp)
m->unsetModifiedDates();

// Force the annotation to sync and generate the XML string
std::string annotation = m->getAnnotationString();

// Assert that the empty Description detritus was completely removed
size_t found = annotation.find("<rdf:Description rdf:about=\"#foo\"/>");
fail_unless(found == std::string::npos);

delete d;
delete m;
}
END_TEST

Suite *
create_suite_SBase (void)
{
Expand Down Expand Up @@ -2709,6 +2738,7 @@ create_suite_SBase (void)
tcase_add_test(tcase, test_SBase_userData1);

tcase_add_test(tcase, test_SBase_prefixMetaIdSBO);
tcase_add_test(tcase, test_SBase_unsetModifiedDates_issue354);

suite_add_tcase(suite, tcase);

Expand Down
Loading