mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-18 12:28:31 +01:00
Add a workaround for broken XML entities in ASX playlists
This commit is contained in:
parent
3dce88f94a
commit
1344103515
@ -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);
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user