Fix checking for non-empty string in prefix check

This commit is contained in:
Patrick Niklaus 2018-03-29 16:10:26 +00:00 committed by Patrick Niklaus
parent 5a68f4c214
commit 39effb8f7e
2 changed files with 5 additions and 1 deletions

View File

@ -35,7 +35,7 @@ namespace detail
inline std::string trimName(const std::string &name_prefix, const std::string &name) inline std::string trimName(const std::string &name_prefix, const std::string &name)
{ {
// list directory and // list directory and
if (name_prefix.back() == '/') if (!name_prefix.empty() && name_prefix.back() == '/')
{ {
auto directory_position = name.find_first_of("/", name_prefix.length()); auto directory_position = name.find_first_of("/", name_prefix.length());
// this is a "file" in the directory of name_prefix // this is a "file" in the directory of name_prefix

View File

@ -93,6 +93,10 @@ BOOST_AUTO_TEST_CASE(layout_list_test)
layout.List("/mld/metrics/", std::back_inserter(results_5)); layout.List("/mld/metrics/", std::back_inserter(results_5));
layout.List("/mld/", std::back_inserter(results_6)); layout.List("/mld/", std::back_inserter(results_6));
std::vector<std::string> results_7;
layout.List("", std::back_inserter(results_7));
BOOST_CHECK_EQUAL(results_7.size(), 7);
CHECK_EQUAL_RANGE( CHECK_EQUAL_RANGE(
results_1, "/ch/edge_filter/block1", "/ch/edge_filter/block2", "/ch/edge_filter/block3"); results_1, "/ch/edge_filter/block1", "/ch/edge_filter/block2", "/ch/edge_filter/block3");
CHECK_EQUAL_RANGE( CHECK_EQUAL_RANGE(