From fb5efd8fa006ee6c7bf8328991b9e31f916ba02c Mon Sep 17 00:00:00 2001 From: emeric Date: Sun, 6 Apr 2025 10:59:32 +0200 Subject: [PATCH] Trim parsed values in ArtistInfo, ref #657 --- src/libs/metadata/impl/ArtistInfo.cpp | 13 +++++++------ src/libs/metadata/test/ArtistInfo.cpp | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/libs/metadata/impl/ArtistInfo.cpp b/src/libs/metadata/impl/ArtistInfo.cpp index 7fd35a2e..639bbd42 100644 --- a/src/libs/metadata/impl/ArtistInfo.cpp +++ b/src/libs/metadata/impl/ArtistInfo.cpp @@ -23,6 +23,7 @@ #include #include "core/ILogger.hpp" +#include "core/String.hpp" namespace lms::metadata { @@ -43,12 +44,12 @@ namespace lms::metadata const auto& artistNode{ root.get_child("artist") }; - artistInfo.mbid = core::UUID::fromString(artistNode.get_optional("musicBrainzArtistID").value_or("")); - artistInfo.name = artistNode.get_optional("name").value_or(""); - artistInfo.sortName = artistNode.get_optional("sortname").value_or(""); - artistInfo.type = artistNode.get_optional("type").value_or(""); - artistInfo.gender = artistNode.get_optional("gender").value_or(""); - artistInfo.disambiguation = artistNode.get_optional("disambiguation").value_or(""); + artistInfo.mbid = core::UUID::fromString(core::stringUtils::stringTrim(artistNode.get_optional("musicBrainzArtistID").value_or(""))); + artistInfo.name = core::stringUtils::stringTrim(artistNode.get_optional("name").value_or("")); + artistInfo.sortName = core::stringUtils::stringTrim(artistNode.get_optional("sortname").value_or("")); + artistInfo.type = core::stringUtils::stringTrim(artistNode.get_optional("type").value_or("")); + artistInfo.gender = core::stringUtils::stringTrim(artistNode.get_optional("gender").value_or("")); + artistInfo.disambiguation = core::stringUtils::stringTrim(artistNode.get_optional("disambiguation").value_or("")); artistInfo.biography = artistNode.get_optional("biography").value_or(""); return artistInfo; diff --git a/src/libs/metadata/test/ArtistInfo.cpp b/src/libs/metadata/test/ArtistInfo.cpp index e1e86374..4410cf2b 100644 --- a/src/libs/metadata/test/ArtistInfo.cpp +++ b/src/libs/metadata/test/ArtistInfo.cpp @@ -76,4 +76,22 @@ He moved from the UK to Montreal in 1984 to become resident DJ at a number of cl ASSERT_EQ(artistInfo.disambiguation, "Timothy Taylor"); ASSERT_EQ(artistInfo.biography, "DJ and producer based in London, UK. Founder of Missile Records and Planet Of Drums.\r\n\r\nHe moved from the UK to Montreal in 1984 to become resident DJ at a number of clubs. In 1987, he began working as an A&R for JSE Agency & Management in New York, managing the likes of Tommy Musto, Frankie Bones, and The KLF. He also arranged and was tour manager for artists such as Womack & Womack, Jungle Brothers, Ice-T, and Guru Josh."); } + + TEST(ArtistInfo, trim) + { + std::istringstream is{ R"( + + My Artist + 38811c52-85e3-4e2e-3319-ab7d9f2cfa5b + Artist, My + My Artist +)" }; + + const ArtistInfo artistInfo{ parseArtistInfo(is) }; + + EXPECT_EQ(artistInfo.mbid, core::UUID::fromString("38811c52-85e3-4e2e-3319-ab7d9f2cfa5b")); + EXPECT_EQ(artistInfo.name, "My Artist"); + ASSERT_EQ(artistInfo.sortName, "Artist, My"); + ASSERT_EQ(artistInfo.disambiguation, "My Artist"); + } } // namespace lms::metadata::tests \ No newline at end of file