From f00e1d74931f74d66f172e78f669309a5b60e7ba Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 19 Jul 2024 16:11:22 +1000 Subject: Fix track ids containing '\n' not decoding properly This has been the cause of the elusive "selecting a track opens it like an index" bug :) --- src/tangara/database/records.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/tangara/database/records.cpp') diff --git a/src/tangara/database/records.cpp b/src/tangara/database/records.cpp index 88ddbd91..3e76ecad 100644 --- a/src/tangara/database/records.cpp +++ b/src/tangara/database/records.cpp @@ -19,6 +19,7 @@ #include "cppbor.h" #include "cppbor_parse.h" +#include "debug.hpp" #include "esp_log.h" #include "database/index.hpp" @@ -229,16 +230,16 @@ auto ParseIndexKey(const leveldb::Slice& slice) -> std::optional { std::istringstream in(key_data.substr(header_length + 1)); std::stringbuf buffer{}; + // FIXME: what if the item contains a '\0'? Probably we make a big mess. in.get(buffer, kFieldSeparator); if (buffer.str().size() > 0) { result.item = buffer.str(); } - buffer = {}; - in.get(buffer); - std::string id_str = buffer.str(); + std::string id_str = + key_data.substr(header_length + 1 + buffer.str().size() + 1); if (id_str.size() > 1) { - result.track = BytesToTrackId(id_str.substr(1)); + result.track = BytesToTrackId(id_str); } return result; @@ -252,6 +253,7 @@ auto BytesToTrackId(std::span bytes) -> std::optional { auto [res, unused, err] = cppbor::parse( reinterpret_cast(bytes.data()), bytes.size()); if (!res || res->type() != cppbor::UINT) { + ESP_LOGE(kTag, "Track ID parsing failed!!"); return {}; } return res->asUint()->unsignedValue(); -- cgit v1.2.3 From be9564d1c7ef2fed3330964472b5ebda557da3d6 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 25 Jul 2024 09:50:31 +1000 Subject: Parse single-byte track ids properly --- src/tangara/database/records.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tangara/database/records.cpp') diff --git a/src/tangara/database/records.cpp b/src/tangara/database/records.cpp index 3e76ecad..6406f080 100644 --- a/src/tangara/database/records.cpp +++ b/src/tangara/database/records.cpp @@ -238,7 +238,7 @@ auto ParseIndexKey(const leveldb::Slice& slice) -> std::optional { std::string id_str = key_data.substr(header_length + 1 + buffer.str().size() + 1); - if (id_str.size() > 1) { + if (id_str.size() > 0) { result.track = BytesToTrackId(id_str); } -- cgit v1.2.3 From 99a3a904e4d9cc2e4d92edbbf1ebbd0892d3918e Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 3 Sep 2024 14:36:54 +1000 Subject: Handle collation text that includes '\0' This seems to be tickled by the ogg comment handling changes (possibly libtags doesn't actually handle this case?) --- src/tangara/database/records.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/tangara/database/records.cpp') diff --git a/src/tangara/database/records.cpp b/src/tangara/database/records.cpp index 6406f080..17009cd8 100644 --- a/src/tangara/database/records.cpp +++ b/src/tangara/database/records.cpp @@ -227,19 +227,15 @@ auto ParseIndexKey(const leveldb::Slice& slice) -> std::optional { return {}; } - std::istringstream in(key_data.substr(header_length + 1)); - std::stringbuf buffer{}; + key_data = key_data.substr(header_length + 1); + size_t last_sep = key_data.find_last_of('\0'); - // FIXME: what if the item contains a '\0'? Probably we make a big mess. - in.get(buffer, kFieldSeparator); - if (buffer.str().size() > 0) { - result.item = buffer.str(); + if (last_sep > 0) { + result.item = key_data.substr(0, last_sep); } - std::string id_str = - key_data.substr(header_length + 1 + buffer.str().size() + 1); - if (id_str.size() > 0) { - result.track = BytesToTrackId(id_str); + if (last_sep + 1 < key_data.size()) { + result.track = BytesToTrackId(key_data.substr(last_sep + 1)); } return result; -- cgit v1.2.3