Skip to content

Commit 1c7f818

Browse files
authored
Merge pull request #918 from phunkyfish/xmltv-format-whitespace
Take account of whitespace at end of xmltv file while doing format check
2 parents cbd3294 + dcda81a commit 1c7f818

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

pvr.iptvsimple/addon.xml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<addon
33
id="pvr.iptvsimple"
4-
version="22.3.0"
4+
version="22.3.1"
55
name="IPTV Simple Client"
66
provider-name="nightik and Ross Nicholson">
77
<requires>@ADDON_DEPENDS@

pvr.iptvsimple/changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v22.3.1
2+
- Take account of whitespace at end of xmltv file while doing format check
3+
14
v22.3.0
25
- PVR Add-on API v9.2.0
36

src/iptvsimple/Epg.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,35 @@ char* Epg::FillBufferFromXMLTVData(std::string& data, std::string& decompressedD
221221
return buffer;
222222
}
223223

224+
namespace {
225+
226+
char GetLastValidCharInBuffer(const char* buffer)
227+
{
228+
size_t charIndex = std::strlen(buffer) - 1;
229+
char lastValidChar = buffer[charIndex];
230+
231+
while (charIndex != 0 &&
232+
(buffer[charIndex] == ' ' ||
233+
buffer[charIndex] == '\t'||
234+
buffer[charIndex] == '\n' ||
235+
buffer[charIndex] == '\r' ||
236+
buffer[charIndex] == '\f' ||
237+
buffer[charIndex] == '\v'))
238+
{
239+
lastValidChar = buffer[--charIndex];
240+
}
241+
242+
return lastValidChar;
243+
}
244+
245+
} // unnamed namespace
246+
224247
const XmltvFileFormat Epg::GetXMLTVFileFormat(const char* buffer)
225248
{
226249
if (!buffer)
227250
return XmltvFileFormat::INVALID;
228251

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

0 commit comments

Comments
 (0)