Skip to content

Commit

Permalink
Merge pull request #918 from phunkyfish/xmltv-format-whitespace
Browse files Browse the repository at this point in the history
Take account of whitespace at end of xmltv file while doing format check
  • Loading branch information
phunkyfish authored Oct 29, 2024
2 parents cbd3294 + dcda81a commit 1c7f818
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="22.3.0"
version="22.3.1"
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 @@
v22.3.1
- Take account of whitespace at end of xmltv file while doing format check

v22.3.0
- PVR Add-on API v9.2.0

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 1c7f818

Please sign in to comment.