Skip to content

Commit

Permalink
Fix a bug to escape slash in binary_to_printable
Browse files Browse the repository at this point in the history
Signed-off-by: Ze Gan <ganze718@gmail.com>
  • Loading branch information
Pterosaur committed Jul 12, 2023
1 parent 8f8d501 commit f4db021
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/stringutility.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static inline std::string binary_to_printable(const void *buffer, size_t length)
{
if (c == '\\')
{
printable.push_back('\\');
printable.push_back('\\\\');
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion tests/stringutility_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ TEST(STRINGUTILITY, binary_to_printable)
EXPECT_EQ(swss::binary_to_printable(a.data(), a.size()), "\\x01\\x02\\x03\\xFF\\x04");

std::array<std::uint8_t, 5> b{0x0, 'a', '\n', '\'', '\\'};
EXPECT_EQ(swss::binary_to_printable(b.data(), b.size()), "\\x00a\\n'\\");
EXPECT_EQ(swss::binary_to_printable(b.data(), b.size()), "\\x00a\\n'\\\\");

EXPECT_EQ(swss::binary_to_printable(nullptr, 0), "");
}
Expand Down

0 comments on commit f4db021

Please sign in to comment.