Fixed badly escaped strings. Fixes #29

This commit is contained in:
emeric
2020-02-07 13:51:04 +01:00
parent 812ea7f614
commit f9aeb34606
2 changed files with 30 additions and 8 deletions
+5 -7
View File
@@ -42,13 +42,8 @@ MediaPlayer::MediaPlayer()
playNext(this, "playNext") playNext(this, "playNext")
{ {
_title = bindNew<Wt::WText>("title"); _title = bindNew<Wt::WText>("title");
_title->setTextFormat(Wt::TextFormat::Plain);
_artist = bindNew<Wt::WAnchor>("artist"); _artist = bindNew<Wt::WAnchor>("artist");
_artist->setTextFormat(Wt::TextFormat::Plain);
_release = bindNew<Wt::WAnchor>("release"); _release = bindNew<Wt::WAnchor>("release");
_release->setTextFormat(Wt::TextFormat::Plain);
wApp->doJavaScript("LMS.mediaplayer.init(" + jsRef() + ")"); wApp->doJavaScript("LMS.mediaplayer.init(" + jsRef() + ")");
@@ -91,28 +86,31 @@ MediaPlayer::loadTrack(Database::IdType trackId, bool play)
LMS_LOG(UI, DEBUG) << "Running js = '" << oss.str() << "'"; LMS_LOG(UI, DEBUG) << "Running js = '" << oss.str() << "'";
_title->setTextFormat(Wt::TextFormat::Plain);
_title->setText(Wt::WString::fromUTF8(track->getName())); _title->setText(Wt::WString::fromUTF8(track->getName()));
if (!artists.empty()) if (!artists.empty())
{ {
_artist->setTextFormat(Wt::TextFormat::Plain);
_artist->setText(Wt::WString::fromUTF8(artists.front()->getName())); _artist->setText(Wt::WString::fromUTF8(artists.front()->getName()));
_artist->setLink(LmsApp->createArtistLink(artists.front())); _artist->setLink(LmsApp->createArtistLink(artists.front()));
} }
else else
{ {
_artist->setText(""); _artist->setText("");
_artist->setLink(Wt::WLink()); _artist->setLink({});
} }
if (track->getRelease()) if (track->getRelease())
{ {
_release->setTextFormat(Wt::TextFormat::Plain);
_release->setText(Wt::WString::fromUTF8(track->getRelease()->getName())); _release->setText(Wt::WString::fromUTF8(track->getRelease()->getName()));
_release->setLink(LmsApp->createReleaseLink(track->getRelease())); _release->setLink(LmsApp->createReleaseLink(track->getRelease()));
} }
else else
{ {
_release->setText(""); _release->setText("");
_release->setLink(Wt::WLink()); _release->setLink({});
} }
wApp->doJavaScript(oss.str()); wApp->doJavaScript(oss.str());
+25 -1
View File
@@ -134,7 +134,31 @@ replaceInString(const std::string& str, const std::string& from, const std::stri
std::string std::string
jsEscape(const std::string& str) jsEscape(const std::string& str)
{ {
return replaceInString(str, "\'", "\\\'"); static const std::unordered_map<char, std::string_view> escapeMap
{
{ '\\', "\\\\" },
{ '\n', "\\n" },
{ '\r', "\\r" },
{ '\t', "\\t" },
{ '"', "\\\"" },
};
std::string escaped;
escaped.reserve(str.length());
for (const char c : str)
{
auto it {escapeMap.find(c)};
if (it == std::cend(escapeMap))
{
escaped += c;
continue;
}
escaped += it->second;
}
return escaped;
} }
bool bool