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?)
custom
jacqueline 8 months ago
parent e6921dc055
commit 99a3a904e4
  1. 4
      src/locale/collation.cpp
  2. 16
      src/tangara/database/records.cpp

@ -89,8 +89,8 @@ GLibCollator::~GLibCollator() {
auto GLibCollator::Transform(const std::string& in) -> std::string { auto GLibCollator::Transform(const std::string& in) -> std::string {
size_t size = glib_strxfrm(NULL, in.c_str(), 0, locale_data_.get()); size_t size = glib_strxfrm(NULL, in.c_str(), 0, locale_data_.get());
char* dest = new char[size + 1]{0}; char* dest = new char[size + 1]{0};
glib_strxfrm(dest, in.c_str(), size, locale_data_.get()); size = glib_strxfrm(dest, in.c_str(), size, locale_data_.get());
std::string out{dest, strnlen(dest, size)}; std::string out{dest, size};
delete[] dest; delete[] dest;
return out; return out;
} }

@ -227,19 +227,15 @@ auto ParseIndexKey(const leveldb::Slice& slice) -> std::optional<IndexKey> {
return {}; return {};
} }
std::istringstream in(key_data.substr(header_length + 1)); key_data = key_data.substr(header_length + 1);
std::stringbuf buffer{}; size_t last_sep = key_data.find_last_of('\0');
// FIXME: what if the item contains a '\0'? Probably we make a big mess. if (last_sep > 0) {
in.get(buffer, kFieldSeparator); result.item = key_data.substr(0, last_sep);
if (buffer.str().size() > 0) {
result.item = buffer.str();
} }
std::string id_str = if (last_sep + 1 < key_data.size()) {
key_data.substr(header_length + 1 + buffer.str().size() + 1); result.track = BytesToTrackId(key_data.substr(last_sep + 1));
if (id_str.size() > 0) {
result.track = BytesToTrackId(id_str);
} }
return result; return result;

Loading…
Cancel
Save