escape html chars in fetched lyrics properly
This commit is contained in:
@@ -34,6 +34,21 @@ size_t write_data(char *buffer, size_t size, size_t nmemb, string data)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EscapeHtml(string &str)
|
||||||
|
{
|
||||||
|
for (int i = str.find("<"); i != string::npos; i = str.find("<"))
|
||||||
|
{
|
||||||
|
int j = str.find(">")+1;
|
||||||
|
str.replace(i, j-i, "");
|
||||||
|
}
|
||||||
|
for (int i = str.find("'"); i != string::npos; i = str.find("'"))
|
||||||
|
str.replace(i, 6, "'");
|
||||||
|
for (int i = str.find("""); i != string::npos; i = str.find("""))
|
||||||
|
str.replace(i, 6, "\"");
|
||||||
|
for (int i = str.find("&"); i != string::npos; i = str.find("&"))
|
||||||
|
str.replace(i, 6, "&");
|
||||||
|
}
|
||||||
|
|
||||||
string GetLyrics(string artist, string song)
|
string GetLyrics(string artist, string song)
|
||||||
{
|
{
|
||||||
const string filename = artist + " - " + song + ".txt";
|
const string filename = artist + " - " + song + ".txt";
|
||||||
@@ -87,30 +102,12 @@ string GetLyrics(string artist, string song)
|
|||||||
if (result == "Not found")
|
if (result == "Not found")
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
for (int i = result.find("'"); i != string::npos; i = result.find("'"))
|
|
||||||
result.replace(i, 6, "'");
|
|
||||||
for (int i = result.find("""); i != string::npos; i = result.find("""))
|
|
||||||
result.replace(i, 6, "\"");
|
|
||||||
for (int i = result.find("<"); i != string::npos; i = result.find("<"))
|
for (int i = result.find("<"); i != string::npos; i = result.find("<"))
|
||||||
result.replace(i, 4, "<");
|
result.replace(i, 4, "<");
|
||||||
for (int i = result.find(">"); i != string::npos; i = result.find(">"))
|
for (int i = result.find(">"); i != string::npos; i = result.find(">"))
|
||||||
result.replace(i, 4, ">");
|
result.replace(i, 4, ">");
|
||||||
for (int i = result.find("<lyric>"); i != string::npos; i = result.find("<lyric>"))
|
|
||||||
result.replace(i, 7, "");
|
EscapeHtml(result);
|
||||||
for (int i = result.find("</lyric>"); i != string::npos; i = result.find("</lyric>"))
|
|
||||||
result.replace(i, 8, "");
|
|
||||||
for (int i = result.find("<lyrics>"); i != string::npos; i = result.find("<lyrics>"))
|
|
||||||
result.replace(i, 8, "");
|
|
||||||
for (int i = result.find("</lyrics>"); i != string::npos; i = result.find("</lyrics>"))
|
|
||||||
result.replace(i, 9, "");
|
|
||||||
for (int i = result.find("<b>"); i != string::npos; i = result.find("<b>"))
|
|
||||||
result.replace(i, 3, "");
|
|
||||||
for (int i = result.find("</b>"); i != string::npos; i = result.find("</b>"))
|
|
||||||
result.replace(i, 4, "");
|
|
||||||
for (int i = result.find("<i>"); i != string::npos; i = result.find("<i>"))
|
|
||||||
result.replace(i, 3, "");
|
|
||||||
for (int i = result.find("</i>"); i != string::npos; i = result.find("</i>"))
|
|
||||||
result.replace(i, 4, "");
|
|
||||||
|
|
||||||
std::ofstream output(fullpath.c_str());
|
std::ofstream output(fullpath.c_str());
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
# include "curl/curl.h"
|
# include "curl/curl.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void EscapeHtml(string &);
|
||||||
string GetLyrics(string, string);
|
string GetLyrics(string, string);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user