Fixed bad handling of utf8 bom for playslit files, fixes #694
This commit is contained in:
@@ -155,15 +155,20 @@ namespace lms::metadata
|
|||||||
accumulatedLyrics.clear();
|
accumulatedLyrics.clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool firstLine{ true };
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(is, line))
|
while (std::getline(is, line))
|
||||||
{
|
{
|
||||||
std::string_view trimmedLine{ core::stringUtils::stringTrimEnd(line) };
|
|
||||||
|
|
||||||
// Remove potential UTF8 BOM
|
// Remove potential UTF8 BOM
|
||||||
constexpr std::string_view utf8BOM{ "\xEF\xBB\xBF" };
|
if (firstLine)
|
||||||
if (trimmedLine.starts_with(utf8BOM))
|
{
|
||||||
trimmedLine = trimmedLine.substr(utf8BOM.size());
|
firstLine = false;
|
||||||
|
constexpr std::string_view utf8BOM{ "\xEF\xBB\xBF" };
|
||||||
|
if (line.starts_with(utf8BOM))
|
||||||
|
line.erase(0, utf8BOM.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string_view trimmedLine{ core::stringUtils::stringTrimEnd(line) };
|
||||||
|
|
||||||
// Skip comments
|
// Skip comments
|
||||||
if (!trimmedLine.empty() && trimmedLine.front() == '#')
|
if (!trimmedLine.empty() && trimmedLine.front() == '#')
|
||||||
|
|||||||
@@ -63,11 +63,21 @@ namespace lms::metadata
|
|||||||
|
|
||||||
PlayList parsePlayList(std::istream& is)
|
PlayList parsePlayList(std::istream& is)
|
||||||
{
|
{
|
||||||
|
bool firstLine{ true };
|
||||||
PlayList playlist;
|
PlayList playlist;
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(is, line))
|
while (std::getline(is, line))
|
||||||
{
|
{
|
||||||
|
// Remove potential UTF8 BOM
|
||||||
|
if (firstLine)
|
||||||
|
{
|
||||||
|
firstLine = false;
|
||||||
|
constexpr std::string_view utf8BOM{ "\xEF\xBB\xBF" };
|
||||||
|
if (line.starts_with(utf8BOM))
|
||||||
|
line.erase(0, utf8BOM.size());
|
||||||
|
}
|
||||||
|
|
||||||
const std::string_view trimmedLine{ core::stringUtils::stringTrim(line) };
|
const std::string_view trimmedLine{ core::stringUtils::stringTrim(line) };
|
||||||
if (trimmedLine.empty())
|
if (trimmedLine.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "metadata/PlayList.hpp"
|
#include "metadata/PlayList.hpp"
|
||||||
|
|
||||||
@@ -51,4 +52,16 @@ one to be/../one to be/normalized/foo.mp3)" };
|
|||||||
EXPECT_EQ(playlist.files[4], "and another one/with relative path/foo.mp3");
|
EXPECT_EQ(playlist.files[4], "and another one/with relative path/foo.mp3");
|
||||||
EXPECT_EQ(playlist.files[5], "one to be/normalized/foo.mp3");
|
EXPECT_EQ(playlist.files[5], "one to be/normalized/foo.mp3");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(PlayList, UTF8_bom)
|
||||||
|
{
|
||||||
|
const unsigned char content[] = { 0xEF, 0xBB, 0xBF, '#', 'E', 'X', 'T', 'M', '3', 'U', '\r', '\n', '\r', '\n', '.', '.', '/', 't', 'e', 's', 't', '.', 'm', 'p', '3', '\r', '\n' };
|
||||||
|
std::istringstream is{ std::string(reinterpret_cast<const char*>(content), sizeof(content)) };
|
||||||
|
|
||||||
|
const PlayList playlist{ parsePlayList(is) };
|
||||||
|
EXPECT_EQ(playlist.name, "");
|
||||||
|
ASSERT_EQ(playlist.files.size(), 1);
|
||||||
|
EXPECT_EQ(playlist.files[0], "../test.mp3");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace lms::metadata::tests
|
} // namespace lms::metadata::tests
|
||||||
@@ -134,9 +134,7 @@ namespace lms::scanner
|
|||||||
if (track)
|
if (track)
|
||||||
playListAssociation.tracks.push_back(TrackInfo{ .trackId = track->getId(), .releaseId = track->getReleaseId() });
|
playListAssociation.tracks.push_back(TrackInfo{ .trackId = track->getId(), .releaseId = track->getReleaseId() });
|
||||||
else
|
else
|
||||||
{
|
|
||||||
pendingErrors.emplace_back(std::make_shared<PlayListFilePathMissingError>(playListFile->getAbsoluteFilePath(), file));
|
pendingErrors.emplace_back(std::make_shared<PlayListFilePathMissingError>(playListFile->getAbsoluteFilePath(), file));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pendingErrors.size() == files.size())
|
if (pendingErrors.size() == files.size())
|
||||||
|
|||||||
Reference in New Issue
Block a user