From 802a84bbb19882358290d354edb82089c9a564e0 Mon Sep 17 00:00:00 2001 From: Evelynne Date: Tue, 21 Jan 2025 10:54:48 +0100 Subject: [PATCH] EscapeJSonArtistTitle --- src/engine/enginebuffer.cpp | 4 ++-- src/osc/oscfunctions.h | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/engine/enginebuffer.cpp b/src/engine/enginebuffer.cpp index 7d0dd3ac3ce..bbf8efefb2b 100644 --- a/src/engine/enginebuffer.cpp +++ b/src/engine/enginebuffer.cpp @@ -578,8 +578,8 @@ void EngineBuffer::slotTrackLoaded(TrackPointer pTrack, if (m_pConfig->getValue(ConfigKey("[OSC]", "OscEnabled"))) { sendTrackInfoToOscClients(m_pConfig, getGroup(), - pTrack->getArtist().toLatin1(), - pTrack->getTitle().toLatin1(), + pTrack->getArtist(), + pTrack->getTitle(), 1, (float)pTrack->getDuration(), 0); diff --git a/src/osc/oscfunctions.h b/src/osc/oscfunctions.h index c391a3a4447..5c53a97cd97 100644 --- a/src/osc/oscfunctions.h +++ b/src/osc/oscfunctions.h @@ -4,9 +4,11 @@ constexpr int OUTPUT_BUFFER_SIZE = 1024; constexpr int IP_MTU_SIZE = 1536; +#include #include #include #include +#include #include #include @@ -22,6 +24,21 @@ enum class DefOscBodyType { FLOATBODY }; +// function to convert and carry special characters in TrackArtist & TrackTitle to ASCII +QString escapeStringToJsonUnicode(const QString& input) { + QString escaped; + for (QChar c : input) { + if (c.isPrint() && c.unicode() < 128) { + // Keep printable ASCII characters as is + escaped += c; + } else { + // Escape non-ASCII and special characters + escaped += QString("\\u%1").arg(c.unicode(), 4, 16, QChar('0')).toUpper(); + } + } + return escaped; +} + void sendOscMessage(const char* receiverIp, int port, osc::OutboundPacketStream& p, @@ -166,7 +183,7 @@ void sendTrackInfoToOscClients(UserSettingsPointer pConfig, oscGroup, "TrackArtist", DefOscBodyType::STRINGBODY, - trackArtist, + escapeStringToJsonUnicode(trackArtist), 0, 0, 0); @@ -174,7 +191,7 @@ void sendTrackInfoToOscClients(UserSettingsPointer pConfig, oscGroup, "TrackTitle", DefOscBodyType::STRINGBODY, - trackTitle, + escapeStringToJsonUnicode(trackTitle), 0, 0, 0);