Skip to content

Commit

Permalink
Fix broken OnEndElement in XML parsing
Browse files Browse the repository at this point in the history
Due to easy to make typos in parts of the code, it wasn’t properly
closing <sparkle:version> elements. Fix by not only correcting the typo,
but organizing the code in a way that prevents such accidents.

Longer term, Expat needs to be replaced with a DOM-based XML API for
safer and more maintainable parsing.

Fixes #123.
  • Loading branch information
vslavik committed Dec 1, 2016
1 parent 6b43dae commit 786d180
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions src/appcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,41 +206,44 @@ void XMLCALL OnEndElement(void *data, const char *name)
{
ContextData& ctxt = *static_cast<ContextData*>(data);

if ( ctxt.in_item && strcmp(name, NODE_RELNOTES) == 0 )
if (ctxt.in_item)
{
ctxt.in_relnotes--;
}
else if ( ctxt.in_item && strcmp(name, NODE_TITLE) == 0 )
{
ctxt.in_title--;
}
else if ( ctxt.in_item && strcmp(name, NODE_DESCRIPTION) == 0 )
{
ctxt.in_description--;
}
else if ( ctxt.in_item && strcmp(name, NODE_MIN_OS_VERSION) == 0 )
{
ctxt.in_min_os_version--;
}
else if ( ctxt.in_link && strcmp(name, NODE_LINK) == 0 )
{
ctxt.in_link--;
}
else if ( ctxt.in_link && strcmp(name, NODE_VERSION) == 0 )
{
ctxt.in_version--;
}
else if ( ctxt.in_shortversion && strcmp(name, NODE_SHORTVERSION) == 0 )
{
ctxt.in_shortversion--;
if (strcmp(name, NODE_RELNOTES) == 0)
{
ctxt.in_relnotes--;
}
else if (strcmp(name, NODE_TITLE) == 0)
{
ctxt.in_title--;
}
else if (strcmp(name, NODE_DESCRIPTION) == 0)
{
ctxt.in_description--;
}
else if (strcmp(name, NODE_MIN_OS_VERSION) == 0)
{
ctxt.in_min_os_version--;
}
else if (strcmp(name, NODE_LINK) == 0)
{
ctxt.in_link--;
}
else if (strcmp(name, NODE_VERSION) == 0)
{
ctxt.in_version--;
}
else if (strcmp(name, NODE_SHORTVERSION) == 0)
{
ctxt.in_shortversion--;
}
}
else if (ctxt.in_channel && strcmp(name, NODE_ITEM) == 0)
{
ctxt.in_item--;
if (is_suitable_windows_item(ctxt.items[ctxt.items.size() - 1]))
XML_StopParser(ctxt.parser, XML_TRUE);
}
else if ( strcmp(name, NODE_CHANNEL) == 0 )
else if (strcmp(name, NODE_CHANNEL) == 0 )
{
ctxt.in_channel--;
// we've reached the end of <channel> element,
Expand Down

0 comments on commit 786d180

Please sign in to comment.