Skip to content

Commit

Permalink
Merge pull request #919 from phunkyfish/xmltv-format-whitespace-omega
Browse files Browse the repository at this point in the history
Take account of whitespace at end of xmltv file while doing format check - Omega
  • Loading branch information
phunkyfish authored Oct 29, 2024
2 parents 226288b + 2b5494e commit 4665d80
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pvr.iptvsimple/addon.xml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon
id="pvr.iptvsimple"
version="21.9.3"
version="21.9.4"
name="IPTV Simple Client"
provider-name="nightik and Ross Nicholson">
<requires>@ADDON_DEPENDS@
Expand Down
3 changes: 3 additions & 0 deletions pvr.iptvsimple/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v21.9.4
- Take account of whitespace at end of xmltv file while doing format check

v21.9.3
- Fix XMLTV format check

Expand Down
25 changes: 24 additions & 1 deletion src/iptvsimple/Epg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,35 @@ char* Epg::FillBufferFromXMLTVData(std::string& data, std::string& decompressedD
return buffer;
}

namespace {

char GetLastValidCharInBuffer(const char* buffer)
{
size_t charIndex = std::strlen(buffer) - 1;
char lastValidChar = buffer[charIndex];

while (charIndex != 0 &&
(buffer[charIndex] == ' ' ||
buffer[charIndex] == '\t'||
buffer[charIndex] == '\n' ||
buffer[charIndex] == '\r' ||
buffer[charIndex] == '\f' ||
buffer[charIndex] == '\v'))
{
lastValidChar = buffer[--charIndex];
}

return lastValidChar;
}

} // unnamed namespace

const XmltvFileFormat Epg::GetXMLTVFileFormat(const char* buffer)
{
if (!buffer)
return XmltvFileFormat::INVALID;

if ((buffer[0] == '\x3C' && buffer[std::strlen(buffer) - 1] == '\x3E') || // Start with < and ends with >
if ((buffer[0] == '\x3C' && GetLastValidCharInBuffer(buffer) == '\x3E') || // Start with < and ends with >
(buffer[0] == '\x3C' && buffer[1] == '\x3F' && buffer[2] == '\x78' && // xml should starts with '<?xml'
buffer[3] == '\x6D' && buffer[4] == '\x6C'))
{
Expand Down

0 comments on commit 4665d80

Please sign in to comment.