Skip to content

Commit

Permalink
- fixed Pipe::escape
Browse files Browse the repository at this point in the history
  • Loading branch information
aschnell committed Mar 22, 2022
1 parent 7342cda commit d3061af
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
10 changes: 5 additions & 5 deletions dbus/DBusMessage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,21 +377,21 @@ namespace DBus
{
string out;

for (string::const_iterator it = in.begin(); it != in.end(); ++it)
for (const char c : in)
{
if (*it == '\\')
if (c == '\\')
{
out += "\\\\";
}
else if ((unsigned char)(*it) > 127)
else if ((unsigned char)(c) > 127)
{
char s[5];
snprintf(s, 5, "\\x%02x", (unsigned char)(*it));
snprintf(s, 5, "\\x%02x", (unsigned char)(c));
out += string(s);
}
else
{
out += *it;
out += c;
}
}

Expand Down
4 changes: 2 additions & 2 deletions dbus/DBusPipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ namespace DBus
{
out += "\\\\";
}
else if (c <= ' ')
else if ((unsigned char)(c) <= ' ')
{
char s[5];
snprintf(s, 5, "\\x%02x", c);
snprintf(s, 5, "\\x%02x", (unsigned char)(c));
out += string(s);
}
else
Expand Down
4 changes: 4 additions & 0 deletions testsuite/dbus-escape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ BOOST_AUTO_TEST_CASE(hihi_unescape)
BOOST_AUTO_TEST_CASE(pipe_escape)
{
BOOST_CHECK_EQUAL(Pipe::escape("hello world\n"), "hello\\x20world\\x0a");

BOOST_CHECK_EQUAL(Pipe::escape("ä"), "ä");
}


BOOST_AUTO_TEST_CASE(pipe_unescape)
{
BOOST_CHECK_EQUAL(Pipe::unescape("hello\\x20world\\x0a"), "hello world\n");

BOOST_CHECK_EQUAL(Pipe::unescape("ä"), "ä");
}

0 comments on commit d3061af

Please sign in to comment.