diff --git a/patches/command_pyroscope.cc b/patches/command_pyroscope.cc index 17e8c758..446d1f27 100644 --- a/patches/command_pyroscope.cc +++ b/patches/command_pyroscope.cc @@ -513,7 +513,8 @@ torrent::Object retrieve_d_custom_if_z(core::Download* download, const torrent:: throw torrent::bencode_error("d.custom.if_z: Missing default argument."); try { - return download->bencode()->get_key("rtorrent").get_key("custom").get_key_string(key); + const std::string& val = download->bencode()->get_key("rtorrent").get_key("custom").get_key_string(key); + return val.empty() ? itr->as_string() : val; } catch (torrent::bencode_error& e) { return itr->as_string(); } diff --git a/tests/commands/misc.txt b/tests/commands/misc.txt index a19d198c..a1413b6c 100644 --- a/tests/commands/misc.txt +++ b/tests/commands/misc.txt @@ -34,6 +34,12 @@ ERROR … convert.time_delta: … must be a value # END # d.custom.if_z +$ rtxmlrpc --repr d.custom.set $(rtxmlrpc download_list | head -n1) test_value '' +0 +$ rtxmlrpc --repr d.custom $(rtxmlrpc download_list | head -n1) test_value +'' +$ rtxmlrpc --repr d.custom.if_z $(rtxmlrpc download_list | head -n1) test_value is_empty +'is_empty' $ rtxmlrpc --repr d.custom.set $(rtxmlrpc download_list | head -n1) test_value d_custom_if_z 0 $ rtxmlrpc --repr d.custom.if_z $(rtxmlrpc download_list | head -n1) test_value default