1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-18 20:34:39 +01:00

Add a workaround for broken XML entities in ASX playlists

This commit is contained in:
David Sansome 2011-01-15 13:58:35 +00:00
parent 3dce88f94a
commit 1344103515
2 changed files with 35 additions and 0 deletions

View File

@ -47,6 +47,18 @@ SongList ASXParser::Load(QIODevice *device, const QString& playlist_path, const
index += ex.matchedLength(); index += ex.matchedLength();
} }
// Some playlists have unescaped & characters in URLs :(
ex.setPattern("(href\\s*=\\s*\")([^\"]+)\"");
index = 0;
while ((index = ex.indexIn(data, index)) != -1) {
QString url = ex.cap(2);
url.replace(QRegExp("&(?!amp;|quot;|apos;|lt;|gt;)"), "&");
QByteArray replacement = (ex.cap(1) + url + "\"").toLocal8Bit();
data.replace(ex.cap(0).toLocal8Bit(), replacement);
index += replacement.length();
}
QBuffer buffer(&data); QBuffer buffer(&data);
buffer.open(QIODevice::ReadOnly); buffer.open(QIODevice::ReadOnly);

View File

@ -70,6 +70,29 @@ TEST_F(ASXParserTest, ParsesMoreThanOneTrackFromXML) {
EXPECT_EQ(Song::Type_Stream, songs[1].filetype()); EXPECT_EQ(Song::Type_Stream, songs[1].filetype());
} }
TEST_F(ASXParserTest, ParsesBrokenXmlEntities) {
QByteArray data =
"<asx version = \"3.0\">"
"<Title>DI.fm</Title>"
"<Author>Digitally Imported Radio</Author>"
"<Copyright>2006 Digitally Imported., Inc</Copyright>"
"<MoreInfo href=\"http://www.di.fm/\" />"
" <entry>"
" <PARAM name=\"HTMLView\" value=\"http://www.di.fm/classictrance/pro/mini_playlist.html\"/>"
" <ref href = \"mms://72.26.204.105/classictrance128k?user=h&pass=xxxxxxxxxxxxxxx\"/>"
" <Title>Classic Trance</Title>"
" <Author>Digitally Imported Premium</Author>"
" </entry>"
"</asx>";
QBuffer buffer(&data);
buffer.open(QIODevice::ReadOnly);
ASXParser parser(NULL);
SongList songs = parser.Load(&buffer);
ASSERT_EQ(1, songs.length());
EXPECT_EQ("mms://72.26.204.105/classictrance128k?user=h&pass=xxxxxxxxxxxxxxx", songs[0].filename());
}
TEST_F(ASXParserTest, SavesSong) { TEST_F(ASXParserTest, SavesSong) {
QByteArray data; QByteArray data;
QBuffer buffer(&data); QBuffer buffer(&data);