diff --git a/src/id.cpp b/src/id.cpp index 2da188f..f197beb 100644 --- a/src/id.cpp +++ b/src/id.cpp @@ -54,9 +54,12 @@ std::ostream& wsrep::operator<<(std::ostream& os, const wsrep::id& id) { const char* ptr(static_cast(id.data())); size_t size(id.size()); - if (static_cast(std::count_if(ptr, ptr + size, ::isalnum)) == size) + if (static_cast( + std::count_if(ptr, ptr + size, + [](char c) { return (::isalnum(c) || c == '\0'); })) + == size) { - return (os << std::string(ptr, size)); + return (os << std::string(ptr, ::strnlen(ptr, size))); } else { diff --git a/test/id_test.cpp b/test/id_test.cpp index 5a87ba1..63dea58 100644 --- a/test/id_test.cpp +++ b/test/id_test.cpp @@ -37,6 +37,15 @@ BOOST_AUTO_TEST_CASE(id_test_uuid) } BOOST_AUTO_TEST_CASE(id_test_string) +{ + std::string id_str("node1"); + wsrep::id id(id_str); + std::ostringstream os; + os << id; + BOOST_REQUIRE(id_str == os.str()); +} + +BOOST_AUTO_TEST_CASE(id_test_string_max) { std::string id_str("1234567890123456"); wsrep::id id(id_str);