From 718a919f55be2163b23ca9aad1bca53834849504 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 11 Sep 2024 16:54:06 +0200 Subject: [PATCH] QueuePage: strip trailing slash from "lsinfo" URI Fixes yet another database completion bug. --- src/QueuePage.cxx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/QueuePage.cxx b/src/QueuePage.cxx index 2fa3e43d..b7f1f15a 100644 --- a/src/QueuePage.cxx +++ b/src/QueuePage.cxx @@ -233,11 +233,16 @@ QueuePage::OnSongChange(const struct mpd_status *status) #ifndef NCMPC_MINI static void -add_dir(Completion &completion, const char *dir, +add_dir(Completion &completion, std::string_view uri, struct mpdclient &c) { + assert(uri.ends_with('/')); + /* strip the trailing slash (because MPD doesn't accept paths + ending with a slash) */ + uri.remove_suffix(1); + completion.clear(); - gcmp_list_from_path(c, dir, completion, GCMP_TYPE_RFILE); + gcmp_list_from_path(c, std::string{uri}.c_str(), completion, GCMP_TYPE_RFILE); } class DatabaseCompletion final : public Completion { @@ -266,7 +271,7 @@ DatabaseCompletion::Pre(std::string_view line) noexcept const auto [it, inserted] = dir_list.emplace(line); if (inserted) /* add directory content to list */ - add_dir(*this, it->c_str(), c); + add_dir(*this, line, c); } } @@ -281,7 +286,7 @@ DatabaseCompletion::Post(std::string_view line, Range range) noexcept /* add directory content to list */ const auto [it, inserted] = dir_list.emplace(line); if (inserted) - add_dir(*this, it->c_str(), c); + add_dir(*this, line, c); } }