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 :)
custom
jacqueline 9 months ago
parent ac54cab319
commit f00e1d7493
  1. 10
      src/tangara/database/records.cpp
  2. 4
      src/util/include/debug.hpp

@ -19,6 +19,7 @@
#include "cppbor.h" #include "cppbor.h"
#include "cppbor_parse.h" #include "cppbor_parse.h"
#include "debug.hpp"
#include "esp_log.h" #include "esp_log.h"
#include "database/index.hpp" #include "database/index.hpp"
@ -229,16 +230,16 @@ auto ParseIndexKey(const leveldb::Slice& slice) -> std::optional<IndexKey> {
std::istringstream in(key_data.substr(header_length + 1)); std::istringstream in(key_data.substr(header_length + 1));
std::stringbuf buffer{}; std::stringbuf buffer{};
// FIXME: what if the item contains a '\0'? Probably we make a big mess.
in.get(buffer, kFieldSeparator); in.get(buffer, kFieldSeparator);
if (buffer.str().size() > 0) { if (buffer.str().size() > 0) {
result.item = buffer.str(); result.item = buffer.str();
} }
buffer = {}; std::string id_str =
in.get(buffer); key_data.substr(header_length + 1 + buffer.str().size() + 1);
std::string id_str = buffer.str();
if (id_str.size() > 1) { if (id_str.size() > 1) {
result.track = BytesToTrackId(id_str.substr(1)); result.track = BytesToTrackId(id_str);
} }
return result; return result;
@ -252,6 +253,7 @@ auto BytesToTrackId(std::span<const char> bytes) -> std::optional<TrackId> {
auto [res, unused, err] = cppbor::parse( auto [res, unused, err] = cppbor::parse(
reinterpret_cast<const uint8_t*>(bytes.data()), bytes.size()); reinterpret_cast<const uint8_t*>(bytes.data()), bytes.size());
if (!res || res->type() != cppbor::UINT) { if (!res || res->type() != cppbor::UINT) {
ESP_LOGE(kTag, "Track ID parsing failed!!");
return {}; return {};
} }
return res->asUint()->unsignedValue(); return res->asUint()->unsignedValue();

@ -31,8 +31,8 @@ inline std::string format_hex_string(std::span<const std::byte> data) {
oss << " "; oss << " ";
} }
int byte_val = (int)byte; int byte_val = (int)byte;
oss << "[0x" << std::uppercase << std::setfill('0') << std::setw(2) oss << std::uppercase << std::setfill('0') << std::setw(2) << std::hex
<< std::hex << byte_val << ']'; << byte_val << ' ';
if (byte_val >= 32 && byte_val < 127) { if (byte_val >= 32 && byte_val < 127) {
ascii_values << (char)byte; ascii_values << (char)byte;
} else { } else {

Loading…
Cancel
Save