diff --git a/src/branches.cpp b/src/branches.cpp index c8765d29..d5a57e3d 100644 --- a/src/branches.cpp +++ b/src/branches.cpp @@ -80,11 +80,8 @@ namespace l uint64_t offset; offset = s_.find_first_not_of("+<>-="); - if(offset > 1) - offset = 2; + *values_ = ((offset != std::string::npos) ? s_.substr(offset) : ""); *instr_ = s_.substr(0,offset); - if(offset != std::string::npos) - *values_ = s_.substr(offset); } static diff --git a/tests/tests.cpp b/tests/tests.cpp index 98e1ca96..1a667f55 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -164,6 +164,16 @@ test_config_update_branches() TEST_CHECK(b.to_string() == "/dir=RW"); TEST_CHECK(b.from_string("/dir") == 0); TEST_CHECK(b.to_string() == "/dir=RW"); + + // error out when no branches left + TEST_CHECK(b.from_string("=/dir") == 0); + TEST_CHECK(b.from_string("-/dir") < 0); + TEST_CHECK(b.from_string("-<") < 0); + TEST_CHECK(b.from_string("->") < 0); + + // error out when setting empty branches + TEST_CHECK(b.from_string("=") < 0); + TEST_CHECK(b.from_string("") < 0); } void