Trim parsed values in ArtistInfo, ref #657

This commit is contained in:
emeric
2025-04-06 10:59:32 +02:00
parent faabb7ec4a
commit fb5efd8fa0
2 changed files with 25 additions and 6 deletions
+7 -6
View File
@@ -23,6 +23,7 @@
#include <boost/property_tree/xml_parser.hpp> #include <boost/property_tree/xml_parser.hpp>
#include "core/ILogger.hpp" #include "core/ILogger.hpp"
#include "core/String.hpp"
namespace lms::metadata namespace lms::metadata
{ {
@@ -43,12 +44,12 @@ namespace lms::metadata
const auto& artistNode{ root.get_child("artist") }; const auto& artistNode{ root.get_child("artist") };
artistInfo.mbid = core::UUID::fromString(artistNode.get_optional<std::string>("musicBrainzArtistID").value_or("")); artistInfo.mbid = core::UUID::fromString(core::stringUtils::stringTrim(artistNode.get_optional<std::string>("musicBrainzArtistID").value_or("")));
artistInfo.name = artistNode.get_optional<std::string>("name").value_or(""); artistInfo.name = core::stringUtils::stringTrim(artistNode.get_optional<std::string>("name").value_or(""));
artistInfo.sortName = artistNode.get_optional<std::string>("sortname").value_or(""); artistInfo.sortName = core::stringUtils::stringTrim(artistNode.get_optional<std::string>("sortname").value_or(""));
artistInfo.type = artistNode.get_optional<std::string>("type").value_or(""); artistInfo.type = core::stringUtils::stringTrim(artistNode.get_optional<std::string>("type").value_or(""));
artistInfo.gender = artistNode.get_optional<std::string>("gender").value_or(""); artistInfo.gender = core::stringUtils::stringTrim(artistNode.get_optional<std::string>("gender").value_or(""));
artistInfo.disambiguation = artistNode.get_optional<std::string>("disambiguation").value_or(""); artistInfo.disambiguation = core::stringUtils::stringTrim(artistNode.get_optional<std::string>("disambiguation").value_or(""));
artistInfo.biography = artistNode.get_optional<std::string>("biography").value_or(""); artistInfo.biography = artistNode.get_optional<std::string>("biography").value_or("");
return artistInfo; return artistInfo;
+18
View File
@@ -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.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."); 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"(<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<artist>
<name> My Artist </name>
<musicBrainzArtistID> 38811c52-85e3-4e2e-3319-ab7d9f2cfa5b </musicBrainzArtistID>
<sortname> Artist, My </sortname>
<disambiguation> My Artist </disambiguation>
</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 } // namespace lms::metadata::tests