From 047e9f7fd0e289ac21e662fc92570a4ee4e45e97 Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 31 May 2018 00:23:01 +0200 Subject: [PATCH] ID3v2: Warn if specified string is no valid position --- id3/id3v2frame.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/id3/id3v2frame.cpp b/id3/id3v2frame.cpp index 30ff1b4..2a863ed 100644 --- a/id3/id3v2frame.cpp +++ b/id3/id3v2frame.cpp @@ -412,7 +412,18 @@ Id3v2FrameMaker::Id3v2FrameMaker(Id3v2Frame &frame, byte version, Diagnostics &d if ((version >= 3 && (m_frameId == Id3v2FrameIds::lTrackPosition || m_frameId == Id3v2FrameIds::lDiskPosition)) || (version < 3 && m_frameId == Id3v2FrameIds::sTrackPosition)) { // track number or the disk number frame - m_frame.makeString(m_data, m_decompressedSize, m_frame.value().toString(), TagTextEncoding::Latin1); + // -> convert the position to string + const auto positionStr(m_frame.value().toString(TagTextEncoding::Latin1)); + // -> warn if value is no valid position (although we just store a string after all) + if (m_frame.value().type() != TagDataType::PositionInSet) { + try { + m_frame.value().toPositionInSet(); + } catch (const ConversionException &) { + diag.emplace_back(DiagLevel::Warning, + argsToString("The track/disk number \"", positionStr, "\" is not of the expected form, eg. \"4/10\"."), context); + } + } + m_frame.makeString(m_data, m_decompressedSize, positionStr, TagTextEncoding::Latin1); } else if ((version >= 3 && m_frameId == Id3v2FrameIds::lLength) || (version < 3 && m_frameId == Id3v2FrameIds::sLength)) { // length frame m_frame.makeString(m_data, m_decompressedSize, ConversionUtilities::numberToString(m_frame.value().toTimeSpan().totalMilliseconds()),