Skip to content

Commit

Permalink
d.custom.if_z: return default also for empty value
Browse files Browse the repository at this point in the history
  • Loading branch information
pyroscope committed Jun 18, 2018
1 parent 234f21b commit 99d99f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion patches/command_pyroscope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
6 changes: 6 additions & 0 deletions tests/commands/misc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 99d99f9

Please sign in to comment.